Forum Moderators: coopster
<form name="form1" method="post" onSubmit="return formvalidation(this)" action="<?php echo $me;?>" >
I have done the javascript validation which works fine when the form is loaded.
But if I type the url while loading basically an empty form submits and I get a blank email.
How do I prevent the page from submitting when it is being loaded and secondly once I submit the data how do I call another page.
Thanx!
The form submitting on the load isn't possible with only the code you provided. it may be done mostly by javascript. Maybe you have some onload function?
If you use mozilla it may be nice to show warnings on sending a non ssl data (menu Edit/Preferences->safety/ssl/warnings) In IE I don't know how to turn it on, but there should be a way.
Best regards and welcome to WebmasterWorld!
Michal Cibor
//this is the form name and action
echo '<form name="updatePro_form" action="updateProfile.php" method="POST" onSubmit="return validate_form();" onReset ="return confirm('Are you sure you want to clear the form?')")';
//this is the form textbox
print "<tr><td width=200 align=right id='fname'><font color='red'>*</font>First Name: </td>";
print "<td width=390 align=left><input type=\"text\" name=\"fname\" value=\"$row[FName]\" ></td></tr>\n";
//javascript to check the form
if (document.updatePro_form.fname.value == "")
{
//alert ( "Please fill in the 'First Name'! " );
alert ( "First Name Error! " );
document.getElementById('fname').style.color='red';
document.updatePro_form.fname.focus();
return false ;
}
else
document.getElementById('fname').style.color='black';
Nothing special and it works. I had a similar problem in IE because I was submitting the form by pressing the enter key and not the "submit" button....
--Nick
I'm attaching the code for you to chack it out.
<HTML>
<HEAD>
<TITLE>SEOpartners</TITLE>
<LINK href="text.css" type=text/css rel=stylesheet>
<LINK rel="STYLESHEET" type="text/css" href="/css.css" >
<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
</HEAD>
<BODY topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">
<br><table border="1" cellspacing="0" width="780" cellpadding="0" align="center" class="GrayBorder">
<tr>
<td width="100%">
<table border="0" cellspacing="0" width="780" cellpadding="0" align="center">
<tr>
<td width="509"><a href="http://www.example.com/offer/" title="SEOpartners">
<img src="./images/logo.jpg" alt="SEOpartners" border="0"></a></td>
<td width="271" align="right" class="small_text1">
<?php include('./pitch.htm');?>
</td>
</tr>
</table>
<table border="0" cellspacing="0" width="780" cellpadding="0">
<tr bgcolor="#CCCCCC">
<td width="60%" height=20 background="/images/bgr_topbar.gif" class=white_nav>
<font color="#CCCCCC"> <a class=white_nav href=./offer.php>Home</a>
¦ <a class=white_nav href=./overview.php>Overview</a> ¦
<a class=white_nav href=./faq.php>FAQ</a> ¦
<a class=white_nav href=./contact.php>Contact</a> </font></td>
<td width="40%" height=20 align=right background="/images/bgr_topbar.gif">
<?php include('./places.htm');?>
</td>
</tr>
</table>
<table border=0 width=100% cellspacing="8" cellpadding="0">
<tr>
<!-- END HEADER -->
<td class=small_text1 valign=top>
<form name="form1" method="post" onSubmit="return formvalidation(this)" action="<?php echo $me;?>" >
<CENTER><p> </p>
<TABLE>
<TR>
<TD colspan="2"><img src="images/green.jpg" height="2" width="100%"></TD>
</TR>
<TR>
<TD colspan="2"><strong><font size="-5">Contact us</font></strong></TD>
</TR>
<TR>
<TD colspan="2"><img src="images/white.jpg" height="10" width="100%"></TD>
</TR>
<TR>
<TD width="144">Name:</TD>
<TD width="174"><input name="name" type="text" size="35"></TD>
</TR>
<TR>
<TD>Email:</TD>
<TD><input name="email" type="text" size="35"></TD>
</TR>
<TR>
<TD>Comment:</TD>
<TD><textarea name="comment" cols="30" rows="7"> </textarea></TD>
</TR>
<TR>
<TD colspan="2"><CENTER>
<input name="submit" type="Submit" value="Submit">
</CENTER></TD>
</TR>
</TABLE>
</CENTER>
</form>
<script language="JavaScript">
var frmvalidator = new Validator("form1");
frmvalidator.addValidation("name","req","Please enter your First Name");
frmvalidator.addValidation("email","maxlen=50");
frmvalidator.addValidation("email","req","Please enter you E-mail address");
frmvalidator.addValidation("email","email");
frmvalidator.addValidation("comment","req","Please enter your Comments");
frmvalidator.addValidation("comment","maxlen=100");
</script>
</td>
<?php
$recipient = 'test@gmail.com';
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$comment = stripslashes($_POST['comment']);
$msg = "Client Details:"."<br>\n"."Name: ".$name." ".$lname."<br>"."Email: ".$email."<br>"."Comments: ".$comment;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
if (mail($recipient, $email, $msg, $headers))
echo nl2br("
");
else
echo "Message failed to send";
//}
?>
<!-- BEGIN FOOTER -->
</tr>
</table>
<table border="0" cellspacing="0" width="780" cellpadding="0">
<tr>
<td width="100%" background="/images/separator01.gif">
<img border="0" src="/images/pix.gif" width="1" height="1"></td>
</tr>
</table>
<table border="0" cellspacing="0" width="780" cellpadding="0">
<tr>
<td width="50%" align="left" class="bottom_nav"> <a class="bottom_nav" href="./overview.php">overview</a>
¦ <a class="bottom_nav" href="./faq.php">faq</a> ¦
<a class="bottom_nav" href="./tos.php">terms of service</a> ¦
<a class="bottom_nav" href="./contact.php">contact</a>
</td>
<td width="50%" height="30" class="small_text2" align="right">
Copyright © 2004-2005 <a href="http://www.example.com/">example.com</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p class=footer_text align=center>Google and PageRank are trademarks of Google Technology Inc. <br>
example is not associated with Google in any way.
</body>
</html>
[edited by: jatar_k at 3:19 pm (utc) on May 14, 2005]
[edit reason] generalized url [/edit]
But it seems to me you need to do some server side validation. Javascript validation is really only good as a convenience for the user. It can't effective guarantee proper input. Robots pretty much don't proccess Javascript and so some of them might trip the script and some people surf the web without Javascript enabled.
If you extend you PHP script to do similiar checks to your Javascript and then only run the mail routine if your checks pass then you should be in good shape.