annoying problem please help!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josboogz
Forum Newbie
Posts: 12
Joined: Thu Feb 06, 2003 5:05 am

annoying problem please help!!

Post 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
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post 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>
josboogz
Forum Newbie
Posts: 12
Joined: Thu Feb 06, 2003 5:05 am

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply