Contact Form not processing all fields

Good day,

My site www.supernet.co.za/contact.html
The contact form there sends through the name email and message but nothing else. if i add in a field for “number” the form does not process it still asks for required field. I have basic php knowledge could some1 please give me a hand. I would like the form to process name email tel message and company. If i add the desired fields into the php doc it does not process the form at all.

Please see form data and php data below.

Thanks in advance !!

<form action="contact.php" method="post" id="contactform"> <ol> <li> <label for="name">First Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li> <li> <label for="email">Your email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li> <li> <label for="number">Number</label> <input id="number" name="number" class="text" /> </li> <li> <label for="subject">Subject</label> <input id="subject" name="subject" class="text" /> </li> <li> <label for="message">Message <span class="red">*</span></label> <textarea id="message" name="message" rows="6" cols="50"></textarea> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" /> </li> </ol> </form>

[php]<?php

if(!$_POST) exit;

$email = $_POST[‘email’];

//$error[] = preg_match(’/\b[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}\b/i’, $POST[‘email’]) ? ‘’ : ‘INVALID EMAIL ADDRESS’;
if(!eregi("^[a-z0-9]+([
\.-][a-z0-9]+)" ."@"."([a-z0-9]+([.-][a-z0-9]+))+"."\.[a-z]{2,}"."$",$email )){
$error.=“Invalid email address entered”;
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array (‘name’,‘email’,‘message’);
$required = array(‘name’,‘email’,‘message’,‘number’);

$your_email = "[email protected]";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
  if(in_array($value,$required)){
	if ($key != 'subject' && $key != 'number') {
	  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
	}
	$email_content .= $value.': '.$_POST[$value]."\n";
  }
}
 
if(@mail($your_email,$email_subject,$email_content)) {
	echo 'Message sent!'; 
} else {
	echo 'ERROR!';
}

}
?>[/php]

Well, it appears you are not clear on forms and posting data.

First, the new items would be added on the form page, but to use this data on your php page, you must use $_POST[‘newitemname’].

I see in your php code where you load email and subject, but, not number. Normally you load variables with all the parts of your form page near the beginning of your PHP code. Something like:

$emailaddress = $_POST[‘email’];
$phonenumber = $_POST[‘number’];
etc…

And then use these in your validation processes.
Or, in the tricky code you show, you create a list of form items and a list of required ones and do fancy compares of all to see which required ones are missing.

Here is a link explaining how to do this. Similar to yours, but, different. Perhaps it will help.
http://www.html-form-guide.com/php-form/php-form-validation.html

Sponsor our Newsletter | Privacy Policy | Terms of Service