Page 1 of 1
Confirm before Commit
Posted: Mon Jul 01, 2002 8:46 am
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
Posted: Mon Jul 01, 2002 9:37 am
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ї'submit'] ) {
case 'Preview':
displayPreview($_POST);
displayForm($_POST);
case 'Submit':
processForm($_POST);
default:
displayForm();
break;
}
function displayPreview( $preview )
{
?>
<h2>Preview</h2>
Username: <?=$previewї'username']?><br />
Email: <?=$previewї'email']?><br />
Password: <?=$previewї'password']?><br />
If everything is okay, you can submit the data.
<hr />
<?
}
function displayForm ( $data=false )
{
?>
<form action="<?=$_SERVERї'PHP_SELF']?>" method="post">
Username: <input type="text" name="username" value="<?=$dataї'username']?>"><br />
Email: <input type="text" name="email" value="<?=$dataї'email']?>">
Password: <input type="password" name="password" value="<?=$dataї'password']?>">
<input type="submit" name="submit" value="Submit">
<input type="submit" name="submit" value="Preview">
</form>
<?
}
function processForm ( $data )
{
// 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. =)
}
?>
Posted: Mon Jul 15, 2002 7:36 am
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ї'submit'])){
switch ( $_POSTї'submit'] ) {
case 'Preview':
displayPreview($_POST);
break;
case 'Cancel':
displayForm($_POST);
break;
case 'Submit':
processForm($_POST);
default:
displayForm();
break;
}
}
else {displayForm(); }
function displayPreview( $preview )
{
?>
<h2>Preview</h2>
<form action="<?=$_SERVERї'PHP_SELF']?>" method="post">
Username: <?=$previewї'username']?>
<input type="hidden" name="username" value="<?=$previewї'username']?>" /><br />
Email: <?=$previewї'email']?>
<input type="hidden" name="email" value="<?=$previewї'email']?>" /> <br />
Password: <?=$previewї'password']?>
<input type="hidden" name="password" value="<?=$previewї'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 />
<?
}
function displayForm ( $data=false )
{
?>
<form action="<?=$_SERVERї'PHP_SELF']?>" method="post">
Username: <input type="text" name="username" value="<?=$dataї'username']?>" /><br />
Email: <input type="text" name="email" value="<?=$dataї'email']?>" /><br />
Password: <input type="password" name="password" value="<?=$dataї'password']?>" /><br />
<input type="submit" name="submit" value="Preview" />
</form>
<?
}
function processForm ( $data )
{
// 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. =)
}
?>