Refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luis Almeida
Forum Commoner
Posts: 33
Joined: Tue Apr 01, 2003 4:22 am

Refresh

Post by Luis Almeida »

Hi all,

I´m new in php so my question may look prety basic.

the thing is, I have the folowing code wich work´s fine but after pressing the submit button every time I refresh the page (F5) it returns allways the same "Submited". How can I "reset" the form after pressing the button so if the user refreshes the page it wont execute the submit button again?

Thank´s in advance

Luis Almeida

Code: Select all

<?

	if ($SUBMIT_BUTTON)
	&#123;
		echo "Submited";
	&#125;
	else
	&#123;
		echo "Not yet Submited";
	&#125;

?>

<form action="" method="post" name="MY_FORM">
	<input name="MY_TEXT" type="text" size="20" maxlength="20">
	<input name="SUBMIT_BUTTON" type="submit">
</form>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

<?php
   session_start();
   if ($SUBMIT_BUTTON) { 
      if(isset($_SESSION["already"]))
          echo "Already submitted";
      else{
         echo "Submited";
         $_SESSION["already"]=true;
      } 
   } else { 
      echo "Not yet Submited"; 
   } 

?> 

<form action="" method="post" name="MY_FORM"> 
   <input name="MY_TEXT" type="text" size="20" maxlength="20"> 
   <input name="SUBMIT_BUTTON" type="submit"> 
</form>
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

I would use the header() function
once they submit the form, redirect them back to the page which will reset all the POST vars and they can refresh the page like they never submitted it.
User avatar
Luis Almeida
Forum Commoner
Posts: 33
Joined: Tue Apr 01, 2003 4:22 am

Post by Luis Almeida »

Thank´s to both of you for helping!!
Post Reply