DarkPrince2005 Posted August 4, 2011 Share Posted August 4, 2011 I'm using a custom code module to construct a form. On submit it validates all fields, while keeping the entered values. The problem however is that instead of keeping the emaill address it displays javascript in the associated text field. Any sollutions? [b]<?php if(isset($_POST["submit"]) && $_POST["submit"] == "Book Now"){ $err = 0; $msg = ""; if(isset($_POST["fname"]) && $_POST["fname"] != ""){ if(!preg_match("/^[a-zA-Z ]/",$_POST["fname"])){ $err++; $msg .= "Your name contains invalid characters.<br />"; } } else { $err++; $msg .= "Please enter your name.<br />"; } if(isset($_POST["company"]) && $_POST["company"] != ""){ if(!preg_match("/^[a-zA-Z0-9 -]+$/i",$_POST["company"])){ $err++; $msg .= "Your company name contains invalid characters.<br />"; } } else { $err++; $msg .= "Please enter your company name.<br />"; } if(isset($_POST["department"]) && $_POST["department"] != ""){ if(!preg_match("/^[a-zA-Z ]/",$_POST["department"])){ $err++; $msg .= "Department contains invalid characters.<br />"; } } else { $err++; $msg .= "Please enter your department.<br />"; } if(isset($_POST["tel"]) && $_POST["tel"] != ""){ if((preg_match("/^[0-9 ]{12}$/",$_POST["tel"])) || (preg_match("/^[0-9 ]{10}$/",$_POST["tel"]))){ } else { $err++; $msg .= "Please enter a valid telephone number.<br />"; } } else { $err++; $msg .= "Please enter a telephone number.<br />"; } if(isset($_POST["cell"]) && $_POST["cell"] != ""){ if((preg_match("/^[0-9 ]{10}$/",$_POST["cell"])) || (preg_match("/^[0-9 ]{12}$/",$_POST["cell"]))){ } else { $err++; $msg .= "Please enter a valid Mobile Number.<br />"; } } else { $err++; $msg .= "Please enter a Mobile Number.<br />"; } if(isset($_POST["fax"]) && $_POST["fax"] != ""){ if((preg_match("/^[0-9 ]{10}$/",$_POST["fax"])) || (preg_match("/^[0-9 ]{12}$/",$_POST["fax"]))){ } else { $err++; $msg .= "Please enter a valid fax number.<br />"; } } if(isset($_POST["pcontact"]) && $_POST["pcontact"] != ""){ if((preg_match("/^[0-9 ]{10}$/",$_POST["pcontact"])) || (preg_match("/^[0-9 ]{12}$/",$_POST["pcontact"]))){ } else { $err++; $msg .= "Please enter a valid contact number.<br />"; } } else { $err++; $msg .= "Please enter a valid contact number.<br />"; } if(isset($_POST["email"]) && $_POST["email"] != ""){ if(!ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $_POST["email"])){ $err++; $msg .= "Please enter a valid email address.<br />"; } } else { $err++; $msg .= "Please enter a email address.<br />"; } if(isset($_POST["pemail"]) && $_POST["pemail"] != ""){ if(!ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $_POST["pemail"])){ $err++; $msg .= "Please enter a valid email address.<br />"; } } else { $err++; $msg .= "Please enter a email address.<br />"; } if($err == 0){ mysql_connect("localhost","root",""); mysql_select_db("dbase"); $sql = mysql_query("insert into table values ('','".$_POST["title"]."','".$_POST["fname"]."','".$_POST["company"]."','".$_POST["department"]."','".$_POST["address"]."','".$_POST["city"]."','".$_POST["tel"]."','".$_POST["cell"]."','".$_POST["fax"]."','".$_POST["email"]."','".$_POST["course_name"]."','".$_POST["sdate"]."','".$_POST["edate"]."','".$_POST["order_number"]."','".$_POST["prev_training"]."','".$_POST["diet_req"]."','".$_POST["pname"]."','".$_POST["pcontact"]."','".$_POST["pemail"]."')") or die (mysql_err()); if($sql){ $msg .= "Your booking form has been successfully sent.<br />"; } } } ?> <form action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post"> <?php echo '<font color="#F00F00">'.$msg.'</font>'; ?> <table> <tr> <td>Title:</td> <td>Name (Printed on Certificate):</td> </tr> <tr> <td><input type="radio" name="title" value="Mr." />Mr. <input type="radio" name="title" value="Mrs." />Mrs.</td> <td><input type="text" name="fname" size="40" value="<?php echo $_POST["fname"]; ?>" /></td> </tr> <tr> <td>Company:</td> <td>Department:</td> </tr> <tr> <td><input type="text" name="company" size="40" value="<?php echo $_POST["company"]; ?>" /></td> <td><input type="text" name="department" size="30" value="<?php echo $_POST["department"]; ?>" /></td> </tr> <tr> <td>Address:</td> <td></td> </tr> <tr> <td colspan="2"><input type="text" name="address" size="80" value="<?php echo $_POST["address"]; ?>" /></td> </tr> <tr> <td>City:</td> <td></td> </tr> <tr> <td><input type="text" name="city" size="30" value="<?php echo $_POST["city"]; ?>" /></td> <td></td> </tr> <tr> <td>Tel:</td> <td>Mobile:</td> </tr> <tr> <td><input type="text" name="tel" size="30" value="<?php echo $_POST["tel"]; ?>" /></td> <td><input type="text" name="cell" size="30" value="<?php echo $_POST["cell"]; ?>" /></td> </tr> <tr> <td>Fax:</td> <td>Email:</td> </tr> <tr> <td><input type="text" name="fax" size="30" value="<?php echo $_POST["fax"]; ?>" /></td> <td><input type="text" name="email" size="40" value="<?php echo htmlentities($_POST["email"]); ?>" /></td> </tr> <tr> <td>Training Course Name:</td> <td></td> </tr> <tr> <td colspan="2"><input type="text" name="course_name" size="60" value="<?php echo $_GET["course_name"]; ?>" /></td> </tr> <tr> <td>Start Date:</td> <td>End Date:</td> </tr> <tr> <td><input type="text" name="sdate" size="20" value="<?php echo $_GET["sdate"]; ?>" /></td> <td><input type="text" name="edate" size="20" value="<?php echo $_GET["edate"]; ?>" /></td> </tr> <tr> <td>Order Number:</td> <td></td> </tr> <tr> <td><input type="text" name="order_number" size="40" value="<?php echo $_POST["order_number"]; ?>" /></td> <td></td> </tr> <tr> <td>Previous Bentley Training:</td> <td></td> </tr> <tr> <td colspan="2"><input type="text" name="prev_training" size="40" value="<?php echo $_POST["prev_training"]; ?>" /></td> </tr> <tr> <td>Special Dietary Requirements:</td> <td></td> </tr> <tr> <td colspan="2"><input type="text" name="diet_req" size="80" value="<?php echo $_POST["diet_req"]; ?>" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"><b>Details of Person Responsible for Payment:</b></td> </tr> <tr> <td>Initials & Surname:</td> <td>Contact Number:</td> </tr> <tr> <td><input type="text" name="pname" size="40" value="<?php echo $_POST["pname"]; ?>" /></td> <td><input type="text" name="pcontact" size="40" value="<?php echo $_POST["pcontact"]; ?>" /></td> </tr> <tr> <td>Email:</td> <td></td> </tr> <tr> <td><input type="text" name="pemail" size="40" value="<?php echo $_POST["pemail"]; ?>" /></td> <td></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Book Now" /></td> </tr> </table> </form>[/b] Quote Link to comment https://forums.phpfreaks.com/topic/243769-email-validation-error/ Share on other sites More sharing options...
DarkPrince2005 Posted August 4, 2011 Author Share Posted August 4, 2011 It's a joomla installation Quote Link to comment https://forums.phpfreaks.com/topic/243769-email-validation-error/#findComment-1251662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.