Hi All

I've checked around all kinds of sites, but to be honest I'm literally just learning PHP and not a clue what people are saying. Basically all I want to do is make some fields required before the form is submitted. At the moment all it does is go to the header:location page when it's submitted! I've probably put something in the wrong place.

My html code is -

<form method="POST" action="contact.php">
          name*<br>
          <input type="text" name="name" size="30">
          <br>
          <br>
          email <br>
          <input type="text" name="email" size="30">
          <br>
          <br>
          message* <br>
          <textarea rows="9" name="message" cols="30"></textarea>
          <br>
          <br>
          <input type="submit" value="Get In Touch" name="submit">
        </form>

and my PHP code is -

<?php ini_set ("POP","mail.conceptcreativedesigns.co.uk");ini_set ("sendmail_from","info@conceptcreativedesigns.co.uk");
if(isset($_POST['submit'])) { 
$to = 'postmaster@conceptcreativedesigns.co.uk'; 
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset-ISO-8859-1\r\n";
$name_field = $_POST['name'];
$email_field = $_POST['email']; 
$message_field = $_POST['message']; 


$subject = 'New Message From - '.$name_field; 

$message = "<html><body>";
$message .= "<b>From:</b>&nbsp;&nbsp;&nbsp;".$name_field;
$message .= "<br><br><b>Email Address:</b>&nbsp;&nbsp;&nbsp;".$email_field;
$message .= "<br><br><b>Message:</b>&nbsp;&nbsp;&nbsp;".$message_field;
$message .="</body></html>";


echo '<script type="text/javascript"> 
window.onload=function(){alert("Thank you, your message has been sent.");} 
</script>'; 
mail($to, $subject, $message, $headers); 
} else { 
echo "I'm sorry, your request had not been submitted. Please try again."; 
} 

header("Location: contact_submit.html#thankyou");
?>

I copied and pasted most of it and got it to where I need it, except for the 'required' bit.

Any suggestions as to what I can include and where to include it would really help!

Thanks

Member Avatar for P0lT10n

I dont understand what is your problem... all the time you will have a redirection to the header code... what is your problem ???

nice but better use regular expression.

good suggestion paulrajj. I appreciate your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.