Jump to content

requesting help please to my contact form


utdfederation

Recommended Posts

hello all i wondering if some kind person could help me out with my contact form as i am new to this.

 

ok the problem i am having is as follows:

i managed to get a file from the net that is just what i'm looking for,problem is when the validation part kicks in i would like to have the error code inline with the relevent boxes that the user has to fill in instead of it all being shown at the top,was wondering if someone could help me out please?

 

php form

<?php

$website_title = "yoursite.com"; //// Enter the name of your website
$subject = "Contact Info for Yoursite.com"; //// Enter a subject line for the notification email
$anti_spam = "777395"; //// Enter a 6 digit antispam code

?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Us</title>
<style type="text/css">
<!--
body {
font: 100.01% Arial, Helvetica, sans-serif;
color: #333333;
text-align: center;
margin: 0px;
padding: 0px;
}
#wrapper {
margin: 10px auto 20px;
width: 600px;
text-align: left;
padding: 0px;
}
#wrapper p {
font-size: 80%;
margin-bottom: 0px;
}

fieldset {
padding-left: 30px;
}

legend {
font-weight: bold;
color: #990000;
}
h5 {
margin-top: 10px;
margin-bottom: 0px;
font-size: 85%;
color: #333333;
}
-->
</style>
</head>

<body>
<br />
<br />

<div id="wrapper">  
<fieldset><legend>Contact Form</legend>
<?php
if (isset($_POST['submitted'])) { // Handle the form.

    //Check for Contact chosen
	if(!empty($_POST['contact'])) {
		$webmaster = ($_POST['contact']);
	} else {
		$webmaster = FALSE;
		echo '<p><font color="red">Please select a <b>Contact!</b></font></p>';
	}

	// Check for a name.
	if (eregi ('^[[:alpha:]\.\' \-]{2,40}$',($_POST['name']))) {
		$n = ucwords(stripslashes(trim($_POST['name'])));
	} else {
		$n = FALSE;
		echo '<p><font color="red">Please enter your <b>name</b>!</font></p>';
	}

	// Check for an email address.
	if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
		$e = ($_POST['email']);
	} else {
		$e = FALSE;
		echo '<p><font color="red">Please enter a valid <b>email address</b>!</font></p>';
	}

	// Check for Comments.
	if(!empty($_POST['comments'])){
		$c = stripslashes($_POST['comments']);
	} else {
		$c = FALSE;
		echo '<p><font color="red">Please enter some <b>Comments!</b></font></p>';
	}

	//check for anti-spam code.
	if(!empty($_POST['anti']) && $_POST['anti'] == "$anti_spam") {
		$a = stripslashes($_POST['anti']);
	} else {
		$a = FALSE;
		echo '<p><font color="red">Please enter the <b>anti-spam code!</b></font></p>';
	}


	if ($n && $e && $c && $a && $webmaster) { // If everything's OK.


//////// ASSIGN THE APPROPRIATE EMAIL ADDRESS FOR EACH CONTACT (case) ////////	
switch ($webmaster) {
case "[email protected]": 		// assign email address for contact1
$subject = "WebContact"; 	// assign subject line for contact1
break;
case "[email protected]": 		// assign email address for contact2
$subject = "WebContact"; 	// assign subject line for contact2
break;
case "[email protected]": 		// assign email address for contact3
$subject = "WebContact"; 	// assign subject line for contact3
break;
} ///////// NOW GO ASSIGN THE SAME EMAIL ADDRESSES ON LINE 175 //////////////

//Sends the email.
$to = "$e";
$body = "**HELLO $n** \n
The following information was submitted to $website_title by you ... \n 
Name: $n \n  
Email: $e \n
User's Comments:\n $c \n ";
$abody = "**ATTENTION $website_title** \n
The following information was submitted by: \n 
Name: $n \n  
Email: $e \n
User's Comments:\n $c \n ";
mail($webmaster,$subject,$abody,"From: $e");
mail($to,$subject,$body,"From: $webmaster");


			// Finish the page.
			echo "<font color=\"#39355A\"><br /><h4>Thank You $n. <br />
				You have submitted the following:</h4>
			<br /><br />
				  <b>Name:</b> <em>$n</em><br />
                      <b>Email:</b> <em>$e</em><br />
				  <b>Comments:</b> <br />
				  <em>$c</em><br /><br />				  
				  A confirmation E-mail has been sent to your address.<br />
				  <br />
				  <br />
				  <a href=\"contact.php\">Back</a>
				  <br /><br /><br /><br /><br /></font>";
				  //include ('includes/footer.html'); // Include the HTML footer.

			exit();

}


} // End of the main Submit conditional.



?>
<br />
    <form action="contact.php" method="post" name="form1" id="form1">    
  
    <select name="contact">
      <option value="" selected="selected">Please select a Contact</option>
<!--------- INSERT APPROPRIATE EMAIL ADDRESS FOR EACH CONTACT ---------->
      <option value="[email protected]">contact1</option>
      <option value="[email protected]">contact2</option>
      <option value="[email protected]">contact3</option>
    </select>
    <br /><br />

   
	 <h5>Name: </h5>
	 <input name="name" type="text" id="name" size="20" maxlength="40" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" />
	 <br />

    <h5>E-mail:</h5>
    <input name="email" type="text" id="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
    <br />

<br />

    <h5>Inquiries / Comments:</h5> 
    <textarea name="comments" cols="50" rows="10" wrap="virtual" id="comments"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea>
    <br />
    <br />
<br />

<p>Please Enter  Anti Spam Code:<strong><font color="#990000"> <?php echo "$anti_spam"; ?></font></strong></p>
<input name="anti" type="text" id="anti" value="<?php if (isset($_POST['anti'])) echo $_POST['anti']; ?>" size="30" />

<br />
<br />
<br />
    <input name="submit" type="submit" class="frmbutt" value="Submit" />    
    <input name="reset" type="reset" class="frmbutt" id="reset" value="Reset" />
<input type="hidden" name="submitted" value="TRUE" />
    </form>
<br />
<br />
  </fieldset>
</div>
</body>
</html>

ok considering nobody has replied to this it could be the case i have not made my intensions clear i think,so i will try to explain what it is i would like someone to help me on.

 

the code above in my previous message when the user hits submit without filling in the form currently displays the error messages at the top,what i would like someone to help me with is the error messages to be displayed to the right side of the text boxes please but i don't know how or what code to write to enable these error codes to be displayed there.

 

now i know that this is the script that enables the error code to be displayed if the form is not filled in correctly.

 

 

<?php
if (isset($_POST['submitted'])) { // Handle the form.

    //Check for Contact chosen
	if(!empty($_POST['contact'])) {
		$webmaster = ($_POST['contact']);
	} else {

	// Check for a name.
	if (eregi ('^[[:alpha:]\.\' \-]{2,40}$',($_POST['name']))) {
		$n = ucwords(stripslashes(trim($_POST['name'])));
	} else {
		$n = FALSE;
		echo '
	<p><font color="red">Please enter your <b>name</b>!</font></p>';
	}

	// Check for an email address.
	if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
		$e = ($_POST['email']);
	} else {
		$e = FALSE;
		echo '<p><font color="red">Please enter a valid <b>email address</b>!</font></p>';
	}

	// Check for Comments.
	if(!empty($_POST['comments'])){
		$c = stripslashes($_POST['comments']);
	} else {
		$c = FALSE;
		echo '<p><font color="red">Please enter some <b>Comments!</b></font></p>';
	}

	//check for anti-spam code.
	if(!empty($_POST['anti']) && $_POST['anti'] == "$anti_spam") {
		$a = stripslashes($_POST['anti']);
	} else {
		$a = FALSE;
		echo '<p><font color="red">Please enter the <b>anti-spam code!</b></font></p>';
	}


	if ($n && $e && $c && $a && $webmaster) { // If everything's OK.


//////// ASSIGN THE APPROPRIATE EMAIL ADDRESS FOR EACH CONTACT (case) ////////	
switch ($webmaster) {
case "[email protected]": 		// assign email address for Badcrazycarl
$subject = "WebContact"; 				// assign subject line for Badcrazycarl
break;
case "[email protected]": 		// assign email address for Brett
$subject = "WebContact"; 				// assign subject line for Brett
break;
case "[email protected]": 		// assign email address for Beetle
$subject = "WebContact"; 				// assign subject line for Beetle
break;
} 

//Sends the email.
$to = "$e";
$body = "**HELLO $n** \n
The following information was submitted to $website_title by you ... \n 
Name: $n \n  
Email: $e \n
User's Comments:\n $c \n ";
$abody = "**ATTENTION $website_title** \n
The following information was submitted by: \n 
Name: $n \n  
Email: $e \n
User's Comments:\n $c \n ";
mail($webmaster,$subject,$abody,"From: $e");
mail($to,$subject,$body,"From: $webmaster");


			// Finish the page.
			echo "<font color=\"#39355A\"><br />
			<h4>Thank You $n. <br />
				You have submitted the following:</h4>
			<br /><br />
				  <b>Name:</b> <em>$n</em><br />
                      <b>Email:</b> <em>$e</em><br />
				  <b>Comments:</b> <br />
				  <em>$c</em><br /><br />				  
				  A confirmation E-mail has been sent to your address.<br />
				  <br />
				  <br />
				  <a href=\"contact.php\">Back</a>
				  <br /><br /><br /><br /><br /></font>";
				  //include ('includes/footer.html'); // Include the HTML footer.

			exit();

}


} // End of the main Submit conditional.



?>

 

but i would appreciate any help on this matter please.

 

utdfed

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.