Using 'IF.. ELSE' to change variable and use it in 'form action...'
<p>I've created a test form that uses IF.. ELSE to validate data in a simple form. This works ok and any validation messages or errors are posted to the same page (userform.php) to inform the user of success or otherwise. </p>

<p>What I want to do now is take the user to a different page on successful completion of the form. Here's my code so far:</p>

<pre><code>&lt;?php
if (isset($_POST['email'], $_POST['password'])) {
$errors = array ();

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST ['email'];
$password = $_POST ['password'];


if (empty ($firstname) || empty ($lastname) || empty ($email) || empty ($password)) {
$errors [] = "Please complete the form";
}
if (empty($email)) {
$errors [] = "You must enter an email address";
}
if (empty($password)) {
$errors [] = "You must enter a password";
}
if (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE){
$errors[] = "Please enter a valid email address";
}
}
if (!empty ($errors)) {
foreach ($errors as $error) {
echo '&lt;strong&gt;', $error ,'&lt;/strong&gt;&lt;br /&gt;';
$result = "userform.php";
 }
} else {
$result = "confirm.php";
}
?&gt;
&lt;form action="&lt;?php echo $result ?&gt;" method="post"&gt;
</code></pre>

<p>The idea is that the users success or otherwise in completing the form changes the $result variable which is used in the form action. The above code doesn't work, so how would I do it? 
Is it even possible? </p>
