Click to See Complete Forum and Search --> : need PHP help - How to reset fields after info is submitted?


kickbak1
03-22-2006, 05:47 AM
Hi,
I have a contact page that I need help with. Right now, after the surfer inputs their info in all the different fields (name, email, comments, etc...) and hits the 'submit' button, a new sized window pops up and says 'thanks for submitting'.

However, all the info the surfer typed into the fields remain there even after they hit the 'submit' button. What I want to happen is that after they hit the submit button and after the 'thanks for submitting' window pops up, I want all the fields to be cleared.

How can I do this? Any help?

If you want to see what I have right now, check the below link:

www.30milligrams.com/contactpage.html

or to make it easier, the HTML code is below:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<SCRIPT TYPE="text/javascript">

<!--

<!--hide from browsers



//verifying the form "register" before sending to server

//begin EMAILvalidation...searched for code online and my resources were at http://www.smartwebby.com/

function verify(str) {



var at="@"

var dot="."

var lat=str.indexOf(at)

var lstr=str.length

var ldot=str.indexOf(dot)

if (str.indexOf(at)==-1){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.indexOf(at,(lat+1))!=-1){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.indexOf(dot,(lat+2))==-1){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



if (str.indexOf(" ")!=-1){

alert("Invalid E-mail. ie- yourname@domain.com")

return false

}



return true

}



function CheckForm(){

var First_Name=document.CONTACT.FirstName

var Last_Name=document.CONTACT.LastName

var Email=document.CONTACT.Email

var Comments=document.CONTACT.Comments





if ((First_Name.value==null) || (First_Name.value=="")){

alert("Please Enter Your First Name")

First_Name.focus()

return false

}

if ((Last_Name.value==null) || (Last_Name.value=="")){

alert("Please Enter Your Last Name")

Last_Name.focus()

return false

}

if ((Email.value==null)||(Email.value=="")){

alert("Please Enter your Email Address")

Email.focus()

return false

}



if (verify(Email.value)==false){

Email.value=""

Email.focus()

return false

}
if ((Comments.value==null) || (Comments.value=="")){

alert("Please Enter Comments")

Comments.focus()

return false

}





window.open('','formResult','width=215,height=25');

return true



}

//end Email validation

// -->

</SCRIPT>
</head>

<body>
<div id="Layer4" style="position:absolute; left:253px; top:153; width:337px; height:184px; z-index:4">
<form name="CONTACT" method="post" action="filloutform-c.php" onSubmit="return CheckForm()" target="formResult">

<table width="75%" border="0">
<tr>
<td width="43%"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="fixedFontText">First
Name:</span></font></td>
<td width="57%"> <input name="FirstName" type="text" id="FirstName" size="26">
</td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="fixedFontText">Last
Name:</span></font></td>
<td><input name="LastName" type="text" id="LastName" size="26"></td>

</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="fixedFontText">Email
Address:</span></font></td>
<td><input name="Email" type="text" id="Email" size="26"></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="fixedFontText">Comments:</span></font></td>
<td><textarea name="Comments" id="Comments"></textarea></td>
</tr>

</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</div>
</body>
</html>

<script language="JavaScript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;

function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}

function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}

SymRealOnLoad = window.onload;
window.onload = SymOnLoad;

//-->
</script>


If you want to see the PHP file that the above HTML page is calling to, you can see it below here:


<?php # Script 3.12 - filloutform.php

//setting variables to send email
$FN = $_POST['FirstName'];
$LN = $_POST['LastName'];
$EM = $_POST['Email'];
$CM = $_POST['Comments'];

//register the user in the database
if ($FN && $LN && $EM && $CM) {

echo '<title>Contact</title><p><b>Your message has been sent!</b></p>';
$sentemail = true;
}
if ($sentemail) {
$body2me = "First Name: \n '{$_POST['FirstName']}' \n\n
Last Name: \n '{$_POST['LastName']}' \n\n
Email: \n {$_POST['Email']} \n\n
Comments: \n '{$_POST['Comments']}' \n\n";
$myemail = "ed@30milligrams.com";
mail ($myemail,'Contact Page', $body2me);

exit();//quit the script.
} else {//if it didn't run OK
$message = '<p>Your email cannot be sent due to a system error. We apologize for any inconvenience.</p>';
echo $message;
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Contact Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html>


I appreciate any help.

Thanks.

chazzy
03-22-2006, 06:27 AM
this is javascript related. in your main form, you need to reset all of the fields after submit
so something like formname.reset should do it.

kickbak1
03-22-2006, 06:40 AM
ok thanks, i'll look for some more specific help in a javascript forum then. thanks.