I would like to use PHP to validate form data, and then redirect to another page while passing the form’s data as POST variables.
I thought that perhaps I could set the form action as “” so that it comes back to the current page, which would then check the data and redirect if everything was OK (although I’m open to alternative approaches if this approach is not the best idea). For example, the PHP code below would redirect to the current page, use some simplified validation checking for the social security number and email data, and if everything was OK it would redirect somehow:
<?php
$error = FALSE;
if(count($_POST)>0){
$error_check = TRUE;
}
else{
$error_check = FALSE;
}
?>
<form action="" method="POST">
<input maxlength='3' name='ssn1' size='3' value=''>)-<input maxlength='2' name='ssn2' size='2' value=''>-<input maxlength='4' name='ssn3' size='3' value=''>
<?php
if($error_check && (!is_numeric($_POST['ssn1']) || !is_numeric($_POST['ssn2']) || !is_numeric($_POST['ssn3']))){
echo "<br />Error - invalid SSN<br />";
$error = TRUE;
}
?>
<input name='email' size='30' maxlength='80' value=''>
<?php
if($error_check && strpos($_POST['email'], '@')===FALSE){
echo "<br />Error - invalid email<br />";
$error = TRUE;
}
?>
<input type="submit" name="Submit">
</form>
<?php
if($error_check && !$error){
echo "Redirecting...";
//redirect somehow?
}
?>
However I don’t know how to redirect while still passing the data as POST data. Is there some way to do this?