gribbs100
01-05-2012, 11:13 PM
Hello Guys,I have a simple contact form that relies on a php file to parse the message. if a visitor tries to skip a field, an alert box pops open saying to make the corrections. That works fine.
When the fields are filled in correctly, I would like the alert box to also be the way to notify them that the email is sent successfully instead of the current way... which shows a line of txt from the php file on a white page.
I'm a little bit confused on how to change this. If the fields are ok, id like the alert box to say delivered and reset the fields.
Can anybody help? Id appreciate it a lot. these are the 2 files:
FORM
<!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=utf-8" />
<title>-</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
background-color: #1c0000;
color: #FFF;
margin-top: 8px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 27px;
}
</style>
</head>
<body>
<script type="text/javascript">
//email form validation
function everif(str) {
var at="@"
var punct="."
var lat=str.indexOf(at)
var lstr=str.length
var lpunct=str.indexOf(punct)
if (str.indexOf(at)==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Valid email must be entered")
return false
}
if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct,(lat+2))==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(" ")!=-1){
alert("Valid email must be entered")
return false
}
return true
}
function evalid(){
var emailID=document.contact_form.mail
if (everif(emailID.value)==false){
emailID.focus()
return false
}
//empty field validation
var fname=document.contact_form.fname
if ((fname.value==null)||(fname.value=="")){
alert("Fields marqued with * must be entered")
fname.focus()
return false
}
var message=document.contact_form.message
if ((message.value==null)||(message.value=="")){
alert("Fields marqued with * must be entered")
message.focus()
return false
}
return true
}
</script>
<form name="contact_form" method="post" action="mailer2.php" onSubmit="return evalid()">
<table border="0"><tr>
<td height="32" colspan="2">Name<br />
<input name="fname" type="text" size="28" /></td>
</tr>
<tr>
<td colspan="2">Email<br />
<input type="text" name="mail" size="28" /></td>
</tr>
<tr>
<td colspan="2">Phone<br />
<input name="phone" type="text" size="28" onkeypress="return numere(event)" onkeyup="return limitarelungime(this, 10)" /></td>
</tr>
<tr>
<td width="65"> </td>
<td width="170"> </td>
</tr>
<tr>
<td colspan="2"><a href="#" title="Valid Contact Form"></a> Message<br />
<textarea name="message" onkeyup="return limitarelungime(this, 255)" cols="22" rows="5" id="message"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="reset" name="reset" value="Reset" id="reset"/>
<input type="submit" name="Submit" value="Submit" />
<a href="#"></a></td>
</tr>
</table>
</form>
</body>
</html>
PHP
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'info@mydomainname.com';
$fromsubject = 'Website Inquiry';
$subject = 'Website Inquiry';
$from = "mydomainname.com";
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you fo your inquiry. <br/>
We will contact you shortly.<br/>";
mail($to, $subject, $body);
} else {
echo "You must write a message. </br> Please go back to the <a href='/form2.html'>form</a>";
}
?>
When the fields are filled in correctly, I would like the alert box to also be the way to notify them that the email is sent successfully instead of the current way... which shows a line of txt from the php file on a white page.
I'm a little bit confused on how to change this. If the fields are ok, id like the alert box to say delivered and reset the fields.
Can anybody help? Id appreciate it a lot. these are the 2 files:
FORM
<!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=utf-8" />
<title>-</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
background-color: #1c0000;
color: #FFF;
margin-top: 8px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 27px;
}
</style>
</head>
<body>
<script type="text/javascript">
//email form validation
function everif(str) {
var at="@"
var punct="."
var lat=str.indexOf(at)
var lstr=str.length
var lpunct=str.indexOf(punct)
if (str.indexOf(at)==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Valid email must be entered")
return false
}
if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct,(lat+2))==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(" ")!=-1){
alert("Valid email must be entered")
return false
}
return true
}
function evalid(){
var emailID=document.contact_form.mail
if (everif(emailID.value)==false){
emailID.focus()
return false
}
//empty field validation
var fname=document.contact_form.fname
if ((fname.value==null)||(fname.value=="")){
alert("Fields marqued with * must be entered")
fname.focus()
return false
}
var message=document.contact_form.message
if ((message.value==null)||(message.value=="")){
alert("Fields marqued with * must be entered")
message.focus()
return false
}
return true
}
</script>
<form name="contact_form" method="post" action="mailer2.php" onSubmit="return evalid()">
<table border="0"><tr>
<td height="32" colspan="2">Name<br />
<input name="fname" type="text" size="28" /></td>
</tr>
<tr>
<td colspan="2">Email<br />
<input type="text" name="mail" size="28" /></td>
</tr>
<tr>
<td colspan="2">Phone<br />
<input name="phone" type="text" size="28" onkeypress="return numere(event)" onkeyup="return limitarelungime(this, 10)" /></td>
</tr>
<tr>
<td width="65"> </td>
<td width="170"> </td>
</tr>
<tr>
<td colspan="2"><a href="#" title="Valid Contact Form"></a> Message<br />
<textarea name="message" onkeyup="return limitarelungime(this, 255)" cols="22" rows="5" id="message"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="reset" name="reset" value="Reset" id="reset"/>
<input type="submit" name="Submit" value="Submit" />
<a href="#"></a></td>
</tr>
</table>
</form>
</body>
</html>
PHP
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'info@mydomainname.com';
$fromsubject = 'Website Inquiry';
$subject = 'Website Inquiry';
$from = "mydomainname.com";
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you fo your inquiry. <br/>
We will contact you shortly.<br/>";
mail($to, $subject, $body);
} else {
echo "You must write a message. </br> Please go back to the <a href='/form2.html'>form</a>";
}
?>