PDA

View Full Version : Blank emails on some form submittions



Marincky
10-12-2007, 03:52 PM
Seldomly, but still enough to worry about, my client gets emails submitted from a form I made on his site that just reads:

'Values submitted from web site form'

There is no other information that comes through.

His form page is http://www.steppin-out.co.uk/contact.html

Please advise anyone?

Watdaflip
10-12-2007, 07:30 PM
People are probably hitting the submit button without filling in any information. Add validation to the fields so it can't be submitted with empty data

Marincky
10-12-2007, 07:45 PM
People are probably hitting the submit button without filling in any information. Add validation to the fields so it can't be submitted with empty data

Validation has always been there:

A lot of the fields have to be filled in so that can't be the reason...

Marincky
10-12-2007, 08:02 PM
Sorry I gave you the wrong form url. It's this one:

http://www.steppin-out.co.uk/music_menu.html

But as above, it DOES have questions that require filling in.

navaldesign
10-13-2007, 11:06 AM
Since you already have validation, i can only suppose that someone is visiting your action.php page.It is enough to visit the action.php page, to recieve a blank email. You can avoid this either using a session, that will prevent the email submission if no session value is found by the script, or add a validation (in the php script) that will look at all fields, and if all of them are blank, it will not submit.

Add this code as first line of your php script, immediately after <?PHP

if ($_POST == ""){
header ("Location: pagetogoto.html");
exit;
}


replacing pagetogoto.html with the actual page name (can be an error page or simply the index page)

Marincky
10-13-2007, 11:24 AM
When you say immediately after, like... next line?

Like this:

<?PHP
if ($_POST == ""){
header ("Location: index.html");
exit;
}
$mailto = "enquiries@steppin-out.co.uk";
$email = $HTTP_POST_VARS['email'];
if ($email == "") {
$email = $mailto;
}
$mailsubj = "Music Menu Contact Form";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";
}
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
?>

navaldesign
10-13-2007, 11:29 AM
Correct.

However, ABVFP will also perform php validation (those who have Javascript disabled in their browsers will not be able to override the built in Javascript validation) and will automatically perform also a form submission check.

Marincky
10-13-2007, 11:31 AM
Thanks George. I have made the change and hopefully this has now cured my client's problem. I knew you would be along to solve it soon!

Many Thanks

navaldesign
10-14-2007, 06:15 AM
Sorry for this, the above code might not work in some cases, please replace it with this one:

if (count($_POST) == 0){
header ("Location: index.html");
exit;
}

Marincky
10-14-2007, 12:24 PM
Sorry for this, the above code might not work in some cases, please replace it with this one:

if (count($_POST) == 0){
header ("Location: index.html");
exit;
}

It didn't work, I had two more come through. I'll try the new code thank you.

navaldesign
10-14-2007, 05:00 PM
Yes, this one works ok.

At least one of the two blanks that you got was from me, maybe both, i don't remember

Marincky
10-14-2007, 05:38 PM
Ah ok, well thank you for your kind help anyway. It's greatly appreciated.