Page 1 of 1

annoying problem please help!!

Posted: Thu Feb 06, 2003 5:05 am
by josboogz
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

Posted: Thu Feb 06, 2003 5:33 am
by ReDucTor
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>

Posted: Thu Feb 06, 2003 5:47 am
by josboogz
sorry yep just noticed it when i ran it. But i still have the problem of it not stopping if the field is empty. The form keeps posting to its action destination regardless.

Posted: Fri Feb 07, 2003 2:32 am
by twigletmac
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