PDA

View Full Version : Information Required Field



Bluenose
04-03-2006, 06:26 PM
How do i set a field on a form to ''information required'' and if it is set to this, the user MUST input info or the form will reset or tell him he didnt enter info?

navaldesign
04-05-2006, 02:51 PM
ou need a script that will check for empty fields and then, if it finds one, redirects the visitor to an error page. Look at: http://www.vodahost.com/vodatalk/forms/3667-need-help-form-2.html#post26480

Bluenose
04-16-2006, 03:48 PM
Thanks for that but the link you have given has just confused me even more. I know exactly what is needed but cant get it from your convo with bird.

I already am using a script the you provided a while back, which emails me the form and directs the submitter to a thankyou page.

Can i just add the information required script lines to this script i am already using?

If so, could you show me the lines that are needed?

The 2 boxes i need info required for are named ''full name'' and ''email address''.

Any help would be greatly appreciated as i am stuck stuck stuck.

navaldesign
04-16-2006, 05:16 PM
I don't know (or remember) which script you have adopted. Post it here and i'll tell you if you can just add lines, or you need to schange it completely.

Bluenose
04-16-2006, 06:34 PM
<?PHP
$email = $HTTP_POST_VARS[email];
$mailto = "my email address";
$mailsubj = "Contact Us";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("Location: http://www.e-advertz.com/thank_you.html");
?>

this is the script i currently use and adjust for my different forms. On this particular form there are two fields out of four that i wish to be 'info required'', one is a name and one is email address.

navaldesign
04-16-2006, 07:42 PM
<?PHP

@$email = addslashes($_POST['email']);
@$name = addslashes($_POST['name']);

// Validation for empty fields
if (strlen($email) == 0 )
{
header("Location: http://www.e-advertz.com/email_errorpage.html");
exit;
}
if (strlen($name) == 0 )
{
header("Location: http://www.e-advertz.com/name_errorpage.html");
exit;
}

$mailto = "my email address"; //Put your real Vodahost email address here
$mailsubj = "Contact Us";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("Location: http://www.e-advertz.com/thank_you.html");
?>

Create two error pages: email_errorpage.html and name_errorpage.html one for empty email field, and one for empty name field. Of course you can only make one if youwish, but change the script accordingly.

The two required fields are supposed to be called "email" and "name".

Bluenose
04-16-2006, 08:14 PM
mate, yet again your a star, works a treat and more importantly, it all makes sense for the future.

just one little picky thing, IF i was to have 2 error pages and BOTH fields were left empty, which page would the php file default to?

navaldesign
04-16-2006, 08:21 PM
It would first find the email, then the name, as their order is in the script. The blocks are:


if (strlen($email) == 0 )
{
header("Location: http://www.e-advertz.com/email_errorpage.html");
exit;
}




and
if (strlen($name) == 0 )
{
header("Location: http://www.e-advertz.com/name_errorpage.html");
exit;
}


If you want them viceversa, just invert the blocks

navaldesign
04-16-2006, 08:23 PM
And i think Andy128 can take from here the necessary material to create another tutorial, on validating form fields.