TKO Posted November 25, 2012 Share Posted November 25, 2012 I have this code that will call the page and clear it but what im trying to figure out is how to execute the code only when submit button is pressed. <?php $address = "example.php"; $fp = fopen("$address",'w+'); if(!$fp) echo 'not Open'; //----------------------------------- while(!feof($fp)) { fputs($fp,' ',999); } fclose($fp); ?> Thank you Quote Link to comment https://forums.phpfreaks.com/topic/271129-clear-page-with-submit/ Share on other sites More sharing options...
Andy123 Posted November 25, 2012 Share Posted November 25, 2012 (edited) if (isset($_POST['submit_button'])) { // Your code here } This is the way I have always done it, but someone on this forum recently wrote that not all browsers submit a value of submit buttons. I haven't tried to verify this. With the code above, you are relying on this. The value of your submit button (i.e. the text) will be submitted, and therefore the if statement will evaluate to true. You could also do like below: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Post request } This just checks if the request is a post request and technically not if your button was pressed (a post request could be made even if it wasn't, but that's a technicality). Edit: Found it! Please see this post by AyKay47. Edited November 25, 2012 by Andy123 Quote Link to comment https://forums.phpfreaks.com/topic/271129-clear-page-with-submit/#findComment-1394869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.