PDA

View Full Version : Validate form prior to sending to mail processor



CrazyEight
26 Mar 2010, 12:51 PM
I am having problem trying to figure out, if I can validate my form before sending it to mail processor page that sits in the server. If anybody can help, I would really appreciate it. Up to now, I can validate the form, but not able to send it to the mail processor. Or I can send my form to the processor, but the form was not validated. so the user will fill the form and not knowing if the information were correct. Again if anyone can help that would save me some hard time.




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



<head>
<title>Tom validate form</title>
<style type="text/css">
body
{
background:white;
font-size:12px;
font-family:arial;
}
table
{
background:green;
color:white;
font-weight:bold;
}
</style>

<script language="javascript" type="text/javascript">




<!-- hide script from older browsers
function validateForm(Feedback)
{

if(document.forms.Feedback.fullName.value=="")
{
alert("Please enter your full name.");
document.forms.Feedback.fullName.focus();
return false;
}

if(document.forms.Feedback.email.value=="")
{
alert("Please enter your email address.");
document.forms.Feedback.email.focus();
return false;
}

if(document.forms.Feedback.Comments.value=="")
{
alert("Please enter your short comments.");
document.forms.Feedback.Comments.focus();
return false;
}

}
stop hiding script -->
</script>


</script>

</head>

<body>
<form name="Feedback" onSubmit="return validateForm(Feedback);">
<table border="1">

<tr>
<td>Name:</td>
<td><input type="text" name="fullName" length="25"></td>
</tr>

<tr>
<td>Email:</td>
<td><input type="text" name="email" length="25"></td>
</tr>

<tr>
<td>Comments</td>
<td><input type="text" name="Comments" length="25"></td>
</tr>

<tr>
<!--<td><input type="submit" name="submit" value="Submit"></td>
<td><input type="reset" name="reset"></td>
</tr>
<form action="http://www.msu.edu/WSD/form-to-email.php" method="post">

<input type="hidden" name="ToAddress" value="wilenkidi@yahoo.com"/>
<input type="hidden" name="CCAddress" Value="Tom@hotmail.com"/>

</table>
</form>

</body>

ocitydesign
22 Apr 2010, 08:43 PM
I noticed a few errors on the source code you posted. Please try the code listed below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



<head>
<title>Tom validate form</title>
<style type="text/css">
body
{
background:white;
font-size:12px;
font-family:arial;
}
table
{
background:green;
color:white;
font-weight:bold;
}
</style>

<script language="javascript" type="text/javascript">
function validate() {
mNv=mainform.fullname.value;
if (mNv=='') {
alert('Please enter your full name.');
event.returnValue=false;
}
mNv=mainform.email.value;
if (mNv=='') {
alert('Please enter your email address.');
event.returnValue=false;
}
mNv=mainform.Comments.value;
if (mNv=='') {
alert('Please enter your short comments.');
event.returnValue=false;
}
}
</script>

</head>

<body>
<form name="Feedback" action="http://www.msu.edu/WSD/form-to-email.php" method="post" onsubmit="validate();">
<input type="hidden" name="ToAddress" value="wilenkidi@yahoo.com"/>
<input type="hidden" name="CCAddress" Value="Tom@hotmail.com"/>
<table border="1">

<tr>
<td>Name:</td>
<td><input type="text" name="fullName" length="25"></td>
</tr>

<tr>
<td>Email:</td>
<td><input type="text" name="email" length="25"></td>
</tr>

<tr>
<td>Comments</td>
<td><input type="text" name="Comments" length="25"></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Submit">&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" name="reset" value="reset"></td>
</tr>
</table>
</form>

</body>