Jump to content

simple contact form question


forsakenmemory

Recommended Posts

im building a contact form and the form works fine but i just want to tweak it alittle and i dont know quite how.

 

insted of sending the user to a seperate error.htm page i would just like for the error message to appear on the same page this way the user wont lose the information theyve alreay written.

 

ive commented what i what to do on the code..

 

<?php

$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "admin@webdesigndigital.com";
$Subject = "Design Enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Website = Trim(stripslashes($_POST['Website'])); 
$Subject = Trim(stripslashes($_POST['Subject'])); 
$Enquiry = Trim(stripslashes($_POST['Enquiry'])); 


$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Enquiry)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; <--  // I would like to be able to send this to a taget iframe on the 
  exit;                                                                                            // same page if possible. its probably simple i just dont know what it is. ???
}


$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";


$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

 

thanks any help anyone can give is most welcomed

 

thanks in advance.

Link to comment
Share on other sites

First off your code is bloated, Whats up with all the trimming, anyway try this  (what version of php you on cause you write your code to like php 3)

<?php

$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "admin@webdesigndigital.com";
$Subject = "Design Enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Website = Trim(stripslashes($_POST['Website'])); 
$Subject = Trim(stripslashes($_POST['Subject'])); 
$Enquiry = Trim(stripslashes($_POST['Enquiry'])); 
$validationOK = "yes";
if(empty($EmailFrom) || empty($Name) || empty($Enquiry)){
$validationOK = "no";
}
if ($validationOK != "yes") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; 
// I would like to be able to send this to a taget iframe on the 
// same page if possible. its probably simple i just dont know what it is. ???
}
else{
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";
if(mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Link to comment
Share on other sites

no sorry i think you misunderstood. i dont think i explained it very well i wrote some new code doing a different tutorial. in newer php.

 

i need the error message to appear in an iframe on the contact.html page above the contact form.

 

 

contact.php

 

<?php

$youremail = "admin@xxxxxxxxxxx.com";

$thankyou = "ok.htm";

;if($email == ""){
?>
// send to target frame on contact.html page "Please Enter Your Email"<br/>
<?php
;}elseif($name == ""){
?>
// send to target frame on contact.html page "Please Enter Your Name"<br/>
<?php
;}elseif($message == ""){
?>
// send to target frame on contact.html page "Please Enter Your Message"<br/>
<?php
;}else{

$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";

mail($youremail, $subject, $msg, $tel, $name, "From: $email\r\nReply-to: $email\r\n");
?>
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">
<?php
}
?>

 

on this page the error message should appear

 

contact.html

 

	<table align=center border="0" cellspacing="0" cellpadding="0" width="790" bgcolor="ffffff" bordercolorlight="#666666" bordercolordark="#808080">

		   <tr>
       		   	   <td width=220 valign=bottom>
                                   <blockquote>
       ERROR MESSAGE HERE ---------->  <iframe width="215" height="40" src="" scrolling="no" name="errormsg"> </iframe>					   
				   			   <form action="contact.php" method="post">
							   Name:
							   <input type="text" name="name"><br/>
							   Email addess:
							   <input type="text" name="email"><br/>
							   Tel:
							   <input type="text" name="tel"><br/>								   
							   Subject:
							   <input type="text" name="subject"><br/>
							   			   
			   	   </blockquote>	   
   				</td>
					 <td width="1">
					 	 <img src="../images/greygrad.gif" width="1" height="240" alt="webdesign" border="0"><img src="../images/spacer.gif" width="25" height="50" alt="web design" border="0"></td>
					 	 	  <td align=left valign=top>
						 	  	  <iframe width="420" height="250" src="contact_info.html" scrolling="no" name="frame1"></iframe>							 	 
					</td>						 
   			</tr>			
			<tr>
				<td valign=top colspan=3>
					<blockquote>
								Enquiry:<br/>
								<textarea name="message" cols="60" rows="10"></textarea><br/><br/>
								<input type="submit" value="Submit"><br/>
								</form>

					</blockquote>											
				</td>
			</tr>
	</table>


thanks anyone who knows how to code this thank you.

Link to comment
Share on other sites

You need to use javascript if you are going to set the src of the iframe the header on page load, but why?

It's easier to put the logic around the iframe source itself:

if ($validationOK != "yes") {
   $iframeSrc = "error.htm">"; 
}else{
   $iframeSrc = "ok.htm\">"; 
}

// and then in the iframe:
?>
<iframe src="<?= $iframeSrc ?>">

Link to comment
Share on other sites

You need to use javascript if you are going to set the src of the iframe the header on page load, but why?

It's easier to put the logic around the iframe source itself:

if ($validationOK != "yes") {
   $iframeSrc = "error.htm">"; 
}else{
   $iframeSrc = "ok.htm\">"; 
}

// and then in the iframe:
?>
<iframe src="<?= $iframeSrc ?>">

 

ok i see what you mean there but you implimented it to the old code i cant figure how to work it into the new one!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.