Hi all,
I am new to PHP, i have read about the problems encountered with the new PHP 4.2+. But i have a similar problem but running the old PHP 4.1.1.
When running similar code to this
<?php
// Form has been submitted...
if ( isset($_POST['submit']) ) {
if ( empty($_POST['emailAddress']) {
header("Location: emailOkay.php");
} else {
echo 'Email was not entered.';
}
}
?>
<form method="post" action="formTest.php">
Enter an Email: <input type="text" name="emailAddress" />
<input type="submit" name="submit" value="Submit Email Address" />
</form>
My computer ignores the if statements that check if the fields are empty, and posts regardless.
I have tried turning the global variables on and off but with no luck.
However if i leave the Form action empty i.e. "" the if statements that check for empty fields work!
Does anyone know what could be wrong,
thankyou for your time.
Jose
annoying problem please help!!
Moderator: General Moderators
that should actually give a syntax error..
if($_POST['submit'] && !empty($_POST['emailAddress'])) {
header('Location: emailOkay.php');
exit;
} else if($_POST['submit'] && !$_POST['emailAddress']) {
echo "Email was not entered.";
}
?><form method="post" action="formTest.php">
Enter an Email: <input type="text" name="emailAddress" />
<input type="submit" name="submit" value="Submit Email Address" />
</form>
if($_POST['submit'] && !empty($_POST['emailAddress'])) {
header('Location: emailOkay.php');
exit;
} else if($_POST['submit'] && !$_POST['emailAddress']) {
echo "Email was not entered.";
}
?><form method="post" action="formTest.php">
Enter an Email: <input type="text" name="emailAddress" />
<input type="submit" name="submit" value="Submit Email Address" />
</form>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Is formTest.php the same file as the one with the code you posted? If it is a different file the reason why your code is not working is that the first file is not run again when the form is posted so it is being sent straight to the form processing script and not running your validation code. You need to include the validation code in the form processing script if you want it to run.
Mac
Mac