Forum Moderators: coopster
For something like this I might prefer to do everything in a single script.
if ($validating_form_data) {
// Do validation here
// store data in hidden fields, exactly as they
// were done originally
if ($did_not_validate) {
// display resubmit button
}
}
else {
// Collect form data here and submit
}
There's obviously a lot of processing missing from this, but maybe it gives you the idea.
Set up your form to process, but have it refresh the same page and load the values in the input boxes if something has been left out.
Set up a variable when you process. If everything is ok, set it to true and display thanks page. If not just reshow the form.
Example:
<?php
$PROCESS = false;
if (isset($_POST['send']))
{
$name = trim($_POST['name']);
$email = trim($_POST['email']);if (!$name=="" &&!$email=="")
{
//do mail stuff$PROCESS = true;
}
}if (!$PROCESS)
{?>
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="send" value="1">
<table>
<tr>
<td>NAME:</td>
<td><input type="text" name="name" value="<?php echo (isset($_POST['name'])? $name : "");?>"></td>
</tr>
<tr>
<td>E-MAIL:</td>
<td><input type="text" name="email" value="<?php echo (isset($_POST['email'])? $email: "");?>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Send"></td>
</tr>
</table>
</form>
<?php}
else
{?>
<p>Thank you! Message sent!</p>
<?php}
?>
Thats really cheap and nasty, but you should get the idea.
dc
Isn't there a way to array the $_POST vars, stick them in the redirect header or a way to make the user go back, like javascript where it's the same as the back button on the browser (because then the vars are still there!)
What is the action that returns you to the originating page if the data is invalid?
Is it automatic?
Do you display a error message and show a link?
In the validating script I would display the error and provide a button. Now you have everything in a form ready to POST back. Then modify the first script to accept that POST, and to go to the correct part of the script.
If you can do it with headers then it's probably easier, but I'm not the person that can help you with headers... I only do convoluted processes :) Even if you did send a page header, won't you will still have to work out how to get to the correct part of the original script? I believe you mentioned it was a few steps in before you POST for validation.