Jump to content

Clear Page With Submit


TKO

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271129-clear-page-with-submit/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.