0

Hi,

Could someone assist me with this code. It gives me an error message whenever i press the submit button.

It gives me this error message
We are very sorry, but there were error(s) found with the form your submitted.
These errors appear below.
Please go back and fix these errors

Here are the forms

This is the contacts.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- @(#) $Id$ -->
<head>
	<title>Jiomoe Foundation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<meta name="Keywords" content= "jiomoe, jiomoe foundation, youth, youth 

organization"/>
	<meta name="Description" content="" />

	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />

	<link rel="shortcut icon" href="./images/jiomoe-logo.jpg" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="./css/style.css" />
	<link rel="stylesheet" type="text/css" href="./css/customize.css" />
	<link rel="stylesheet" type="text/css" href="./css/layout.css" />


</head> 

<body>
<div id="wrap">
	<div id="header"> 
		<?php
			include("logo.php");
			?>
			</div>
		<div id="breadcrumb">
	
				<ul>
						<li><a href="index.php" 

class="">Home</a></li>
						<li><a href="aboutus.php" class="">About 

Us</a></li>
						<li><a href="programs.php" class="">Our 

Programs</a></li>
						<li><a href="members.php" 

class="">Membership</a></li>
						<li><a href="careers.php" 

class="">Careers</a></li>
						<li><a href="contacts.php" 

class="active">Contacts</a></li>
				</ul>
		</div>

<div id="main-body">
	<div id="content"> 
		<div class="inside">
			<form method="POST" action="mailer.php" form name="contacts">
			<label for="first_name">First Name:*</label><br/>
			   <input type="text" name="first_name" size="19"/><br/>
			   <br/>
                         <label for="Last_name">Last Name:*</label><br/>
			   <input type="text" name="last_name" size="19"/><br/>
			   <br/>

			   <label for="email">Email:*</label><br/>
			   <input type="text" name="email" size="19"/><br/>
			   <br/>
			   <label for="comments">Message:*</label><br/>
			   <textarea rows="9" name="comments" cols="30"></textarea>
			   <br/>
			   <br/>
			   <input type="submit" value="Submit" name="submit"/>
			</form>
		</div>
	</div>

<div id="sidebar"> 
	<div class="inside">
		<div class="border">
			<p>Jiomoe Foundation is a Volunteer, Community based Youth 

initiative
			founded by the Kenyan Youth to eradicate poverty,
			create employment opportunities, market and empower the Youth.</p>
			</div>
			<div class="border">
				<div class="info">Information</div>
					Founded<br/> 2008
			</div>
			<div class="border">
				<div class="info">Links</div>
					<a 

href="http://www.jiomoeclub.net">www.jiomoeclub.net</a><br/>
					<a 

href="http://www.jamhurisoftware.com">www.jamhurisoftware</a><br/>
					<a 

href="http://www.fashtechcomputers.com">www.fashtechcomputers</a><br/>
			</div> 
	</div>
</div>

</div> <!--end of main-body-->

<div id="sidebar-2"> 
	<div class="inside"> 
		<div class="advertisement">
			Contact details
		</div>
		<img src="./images/contact_us.jpg"/><br/>
		<strong>Email: info@jiomoe.org<br/>
		Tel: +254723169577<br/>
		+254734297258</strong>
		<div class="advertisement">
			Find Us
		</div>
			<a 

href="http://www.facebook.com/groups.php?ref=sb#/group.php?gid=98375464670"><img 

src="./images/facebook_badge.gif" border="0"/></a>
	</div>
</div>
		<?php
		include("./include/footer.php");
		?>
</div> <!--end of wrap-->

</body> </html>

This is the mailer.php

<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "info@fashtechcomputers.com, matotien@gmail.com";
	$email_subject = "INQUIRIES";
	
	
	function died($error) {
		// your error code can go here
		echo "We are very sorry, but there were error(s) found with the form your submitted. ";
		echo "These errors appear below.<br /><br />";
		echo $error."<br /><br />";
		echo "Please go back and fix these errors.<br /><br />";
		die();
	}
	
	// validation expected data exists
	if(!isset($_POST['first_name']) ||
		!isset($_POST['last_name']) ||
		!isset($_POST['email']) ||
		!isset($_POST['telephone']) ||
		!isset($_POST['comments'])) {
		died('We are sorry, but there appears to be a problem with the form your submitted.');		
	}
	
	$first_name = $_POST['first_name']; // required
	$last_name = $_POST['last_name']; // required
	$email_from = $_POST['email']; // required
	$telephone = $_POST['telephone']; // not required
	$comments = $_POST['comments']; // required
	
	$error_message = "";
	$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
	$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
  	$error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
  	$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
  	$error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  $string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$telephone)) {
  	$error_message .= 'The Telphone Number you entered does not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
  	died($error_message);
  }
	$email_message = "Form details below.\n\n";
	
	function clean_string($string) {
	  $bad = array("content-type","bcc:","to:","cc:","href");
	  return str_replace($bad,"",$string);
	}
	
	$email_message .= "First Name: ".clean_string($first_name)."\n";
	$email_message .= "Last Name: ".clean_string($last_name)."\n";
	$email_message .= "Email: ".clean_string($email_from)."\n";
	$email_message .= "Telephone: ".clean_string($telephone)."\n";
	$email_message .= "Comments: ".clean_string($comments)."\n";
	
	
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- @(#) $Id$ -->
<head>
	<title>Jiomoe Foundation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<meta name="Keywords" content= "jiomoe, jiomoe foundation, youth, youth organization"/>
	<meta name="Description" content="Jiomoe Foundation is a volunteer community based youth initiative." />

	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />

	<link rel="shortcut icon" href="./images/jiomoe-logo.jpg" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="./css/style.css" />
	<link rel="stylesheet" type="text/css" href="./css/customize.css" />
	<link rel="stylesheet" type="text/css" href="./css/layout.css" />


</head> 

<body>
<div id="wrap">
	<div id="header"> 
		<?php
			include("logo.php");
			?>
			</div>
		<div id="breadcrumb">
	
				<ul>
						<li><a href="index.php" class="">Home</a></li>
						<li><a href="aboutus.php" class="active">About Us</a></li>
						<li><a href="programs.php" class="">Our Programs</a></li>
						<li><a href="members.php" class="">Membership</a></li>
						<li><a href="careers.php" class="">Careers</a></li>
						<li><a href="contacts.php" class="">Contacts</a></li>
				</ul>
		</div>

<div id="main-body">
	<div id="content"> 
		<div class="inside">

<p><b>Your message was sent</b></p>

<p>Your message was successfully sent!
Thank you for contacting us, we will reply
to your inquiry as soon as possible!</p>
<a href="contacts.php"><input type="submit" value="Back"/></a>

	</div>
	</div>

<div id="sidebar"> 
	<div class="inside">
		<div class="border">
			<p>Jiomoe Foundation is a Volunteer, Community based Youth initiative
			founded by the Kenyan Youth to eradicate poverty,
			create employment opportunities, market and empower the Youth.</p>
			</div>
			<div class="border">
				<div class="info">Information</div>
					Founded<br/> 2008
			</div>
			<div class="border">
				<div class="info">Links</div>
					<a href="http://www.jiomoeclub.net">www.jiomoeclub.net</a><br/>
					<a href="http://www.jamhurisoftware.com">www.jamhurisoftware</a><br/>
					<a href="http://www.fashtechcomputers.com">www.fashtechcomputers</a><br/>
			</div> 
	</div>
</div>

</div> <!--end of main-body-->

<div id="sidebar-2"> 
	<div class="inside"> 
		<div class="advertisement">
			Advertisements
		</div>
		<div class="advertisement">
			Find Us
		</div>
			<a href="#"><img src="./images/facebook_badge.gif" border="0"/></a>
	</div>
</div>
		<?php
		include("./include/footer.php");
		?>
</div> <!--end of wrap-->

</body> </html>



<?
}
?>
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Stefano Mtangoo
0

The problem with your code appears to be that the mailer is trying to validate a telephone number however there is no field for telephone number in your form.

You can simply add the field for the phone number if you would like to have it as an option or if you can do without the telephone number you can edit out the validation for the telephone number in the mailer.

I reposted the mailer with the validation for telephone commented out. It should work okay as it is and will give you an idea of where to go from there. Try it out and make the appropriate changes as you see fit.

<?php
if(isset($_POST['email'])) {
 
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "info@fashtechcomputers.com, matotien@gmail.com";
	$email_subject = "INQUIRIES";
 
 
	function died($error) {
		// your error code can go here
		echo "We are very sorry, but there were error(s) found with the form your submitted. ";
		echo "These errors appear below.<br /><br />";
		echo $error."<br /><br />";
		echo "Please go back and fix these errors.<br /><br />";
		die();
	}
 
	// validation expected data exists
	if(!isset($_POST['first_name']) ||
		!isset($_POST['last_name']) ||
		!isset($_POST['email']) ||
		//!isset($_POST['telephone']) ||
		!isset($_POST['comments'])) {
		died('We are sorry, but there appears to be a problem with the form your submitted.');		
	}
 
	$first_name = $_POST['first_name']; // required
	$last_name = $_POST['last_name']; // required
	$email_from = $_POST['email']; // required
	//$telephone = $_POST['telephone']; // not required
	$comments = $_POST['comments']; // required
 
	$error_message = "";
	$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
	$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
  	$error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!eregi($string_exp,$last_name)) {
  	$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
  	$error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
 /* $string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$telephone)) {
  	$error_message .= 'The Telphone Number you entered does not appear to be valid.<br />';
  }*/
  if(strlen($error_message) > 0) {
  	died($error_message);
  }
	$email_message = "Form details below.\n\n";
 
	function clean_string($string) {
	  $bad = array("content-type","bcc:","to:","cc:","href");
	  return str_replace($bad,"",$string);
	}
 
	$email_message .= "First Name: ".clean_string($first_name)."\n";
	$email_message .= "Last Name: ".clean_string($last_name)."\n";
	$email_message .= "Email: ".clean_string($email_from)."\n";
	$email_message .= "Telephone: ".clean_string($telephone)."\n";
	$email_message .= "Comments: ".clean_string($comments)."\n";
 
 
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- include your own success html here -->
 
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- @(#) $Id$ -->
<head>
	<title>Jiomoe Foundation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<meta name="Keywords" content= "jiomoe, jiomoe foundation, youth, youth organization"/>
	<meta name="Description" content="Jiomoe Foundation is a volunteer community based youth initiative." />
 
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
 
	<link rel="shortcut icon" href="./images/jiomoe-logo.jpg" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="./css/style.css" />
	<link rel="stylesheet" type="text/css" href="./css/customize.css" />
	<link rel="stylesheet" type="text/css" href="./css/layout.css" />
 
 
</head> 
 
<body>
<div id="wrap">
	<div id="header"> 
		<?php
			include("logo.php");
			?>
			</div>
		<div id="breadcrumb">
 
				<ul>
						<li><a href="index.php" class="">Home</a></li>
						<li><a href="aboutus.php" class="active">About Us</a></li>
						<li><a href="programs.php" class="">Our Programs</a></li>
						<li><a href="members.php" class="">Membership</a></li>
						<li><a href="careers.php" class="">Careers</a></li>
						<li><a href="contacts.php" class="">Contacts</a></li>
				</ul>
		</div>
 
<div id="main-body">
	<div id="content"> 
		<div class="inside">
 
<p><b>Your message was sent</b></p>
 
<p>Your message was successfully sent!
Thank you for contacting us, we will reply
to your inquiry as soon as possible!</p>
<a href="contacts.php"><input type="submit" value="Back"/></a>
 
	</div>
	</div>
 
<div id="sidebar"> 
	<div class="inside">
		<div class="border">
			<p>Jiomoe Foundation is a Volunteer, Community based Youth initiative
			founded by the Kenyan Youth to eradicate poverty,
			create employment opportunities, market and empower the Youth.</p>
			</div>
			<div class="border">
				<div class="info">Information</div>
					Founded<br/> 2008
			</div>
			<div class="border">
				<div class="info">Links</div>
					<a href="http://www.jiomoeclub.net">www.jiomoeclub.net</a><br/>
					<a href="http://www.jamhurisoftware.com">www.jamhurisoftware</a><br/>
					<a href="http://www.fashtechcomputers.com">www.fashtechcomputers</a><br/>
			</div> 
	</div>
</div>
 
</div> <!--end of main-body-->
 
<div id="sidebar-2"> 
	<div class="inside"> 
		<div class="advertisement">
			Advertisements
		</div>
		<div class="advertisement">
			Find Us
		</div>
			<a href="#"><img src="./images/facebook_badge.gif" border="0"/></a>
	</div>
</div>
		<?php
		include("./include/footer.php");
		?>
</div> <!--end of wrap-->
 
</body> </html>
 
 
 
<?
}
?>

Edited by CFROG: n/a

0

Hallos,

This is great. This is my first php application to run successfully.

Another question.

How do i make the error messages to appear on the same page/window if a required field is left out.

Pliz provide me the code if you can.

Regards

0

In order to do that you would need to use some sort of Java or Ajax validation for your fields or have the mailer.php on the same page as contacts.php and have the form method post to itself. I only have a few minutes right now so I can't really get into it.

With this being your first php application to run successfully I would say that your best bet is to just keep it the way that it is now. Your form is "sticky" so to speak therefore none of your information has to be filled in again when you hit back on the browser in the event of an error.

If you are intent on having the error reporting occur on the same page you can Google form validation using Java to have a look and see what you are up against.

0
alert("Field XYZ is empty, please Fill it out!");

You, just make a JavaScript function to handle validation and only allow to submit when things are ok. That will do relieve a server also

Edited by Stefano Mtangoo: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.