Confirm before Commit

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
garriepowers
Forum Newbie
Posts: 3
Joined: Mon Jul 01, 2002 8:46 am
Location: London,UK

Confirm before Commit

Post by garriepowers »

I have a form which, when the user click the SUBMIT button, I would like to display a page listing all the details they have entered.
This would give them the option to either Accept or Reject the details. If they select Reject, I would like to return to the form, with all the details filled in. If the select Accept, I would like to add the details to the database.
How do I create the Accept/Reject page?
Many thanks.
Garrie
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Here's a script jason wrote. It's not exactly what you need, but it is very similar, and you can adapt the basic concept to fit your needs. ( I changed GLOBAL to _SERVER because $GLOBAL['PHP_SELF'] didn't work for me. )

Code: Select all

<?php 

switch ( $_POST&#1111;'submit'] ) &#123; 
   case 'Preview': 
      displayPreview($_POST); 
      displayForm($_POST); 
   case 'Submit': 
      processForm($_POST); 
   default: 
      displayForm(); 
      break; 
&#125; 

function displayPreview( $preview ) 
&#123; 
?> 
<h2>Preview</h2> 
Username: <?=$preview&#1111;'username']?><br /> 
Email: <?=$preview&#1111;'email']?><br /> 
Password: <?=$preview&#1111;'password']?><br /> 
If everything is okay, you can submit the data. 
<hr /> 
<? 
&#125; 

function displayForm ( $data=false ) 
&#123; 
?> 
<form action="<?=$_SERVER&#1111;'PHP_SELF']?>" method="post"> 
   Username: <input type="text" name="username" value="<?=$data&#1111;'username']?>"><br /> 
   Email: <input type="text" name="email" value="<?=$data&#1111;'email']?>"> 
   Password: <input type="password" name="password" value="<?=$data&#1111;'password']?>"> 
   <input type="submit" name="submit" value="Submit"> 
   <input type="submit" name="submit" value="Preview"> 
</form> 
<? 
&#125; 

function processForm ( $data ) 
&#123; 
   // Take the data and actually process this data.  After that 
   // simply use header("Location: something.php") to a result page 
   // after they submit data.  This also prevents people from accidently 
   // entering the same data twice by reloading the page. =) 
&#125; 

?>
garriepowers
Forum Newbie
Posts: 3
Joined: Mon Jul 01, 2002 8:46 am
Location: London,UK

Post by garriepowers »

RE,

Thanks for the reply.

I have made some changes to the example you sent me to produce the behaviour I wanted. I enclose the code below.

Garrie

Code: Select all

<?php 

if (isset($_POST&#1111;'submit']))&#123;
   switch ( $_POST&#1111;'submit'] ) &#123; 

      case 'Preview': 
         displayPreview($_POST); 
         break;

      case 'Cancel':
         displayForm($_POST); 
         break; 

      case 'Submit': 
         processForm($_POST); 

      default: 
         displayForm(); 
         break; 
   &#125;
&#125;
else &#123;displayForm(); &#125;
 

function displayPreview( $preview ) 
&#123; 
?> 
<h2>Preview</h2> 
<form action="<?=$_SERVER&#1111;'PHP_SELF']?>" method="post">

   Username: <?=$preview&#1111;'username']?>
<input type="hidden" name="username" value="<?=$preview&#1111;'username']?>" /><br />
   Email:    <?=$preview&#1111;'email']?>
<input type="hidden" name="email" value="<?=$preview&#1111;'email']?>" /> <br />
   Password: <?=$preview&#1111;'password']?>
<input type="hidden" name="password" value="<?=$preview&#1111;'password']?>" /><br />

   <p>If everything is okay, you can submit the data. </p>

   <input type="submit" name="submit" value="Cancel" />   <input type="submit" name="submit" value="Submit" /> 

</form>
<hr /> 
<? 
&#125; 

function displayForm ( $data=false ) 
&#123; 
?> 
<form action="<?=$_SERVER&#1111;'PHP_SELF']?>" method="post"> 

   Username: <input type="text" name="username" value="<?=$data&#1111;'username']?>" /><br />
   Email:    <input type="text" name="email" value="<?=$data&#1111;'email']?>" /><br />
   Password: <input type="password" name="password" value="<?=$data&#1111;'password']?>" /><br />

   <input type="submit" name="submit" value="Preview" />
</form> 
<? 
&#125; 

function processForm ( $data ) 
&#123; 
   // Take the data and actually process this data.  After that 
   // simply use header("Location: something.php") to a result page 
   // after they submit data.  This also prevents people from accidently 
   // entering the same data twice by reloading the page. =) 

&#125; 

?>
Post Reply