Forum Moderators: coopster

Message Too Old, No Replies

Required Field Script

I need a PHP Script

         

joe1182

2:33 pm on Nov 19, 2004 (gmt 0)

10+ Year Member



Can someone please help me out with my script? I would like to make the 'email' and/or 'name' field required. If it is not filled in I would like it to display an error message but, if it is filled in correctly I would like it to redirect to "thankyou.html". Can anyone help me out? Below I have pasted my current script. Thanks

<?
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$message = $_POST['message'];
$quote = $_POST['quote'];
$question = $_POST['question'];
mail("myemail@mydomain.com", "Website Inquiry",
"Quote: $quote\Question: $question\n $message\n", "From: $name <$email>" );
header("Location: /thankyou.html" );
?>

mincklerstraat

2:51 pm on Nov 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could try:

<? 
$required = array('email', 'name');
foreach($required as $v){
if(empty($_POST[$v])){
echo 'sorry, '.htmlspecialchars($v).' needs to be filled in';
die();
}
}
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$message = $_POST['message'];
$quote = $_POST['quote'];
$question = $_POST['question'];
mail("myemail@mydomain.com", "Website Inquiry",
"Quote: $quote\Question: $question\n $message\n", "From: $name <$email>" );
header("Location: /thankyou.html" );
?>

However, if you're not sure how to do this type of thing, and don't really have the time yet to figure out exactly how to code your form the way you want, [phpformgen.sourceforge.net...] might be for you.

joe1182

3:08 pm on Nov 19, 2004 (gmt 0)

10+ Year Member



Thank you. I was able to tweak this a little bit and get it to work. Again thanks.