|
Mav44 -> RE: Form Email and Field Validation in PHP (3/4/2008 20:45:07)
|
Here goes! My Form Page -------------------------------------- <html> <head> <TITLE>My Site</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251"> <meta http-equiv="Content-Language" content="en-us"> <script type='text/javascript'> function formValidator(){ // Make quick references to our fields var name = document.getElementById('name'); var Phone_Number = document.getElementById('Phone_Number'); var Email = document.getElementById('Email'); // Check each input in the order that it appears in the form! if(madeSelection(name, "Please enter a valid name")){ if(madeSelection(Phone_Number, "Please enter a valid phone number")){ if(emailValidator(Email, "Please enter a valid email address")){ return true; } } } return false; } function isEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); // set the focus to this input return true; } return false; } function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[0-9a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function lengthRestriction(elem, min, max){ var uInput = elem.value; if(uInput.length >= min && uInput.length <= max){ return true; }else{ alert("Please enter between " +min+ " and " +max+ " characters"); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } function emailValidator(elem, helperMsg){ var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; if(elem.value.match(emailExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } </script> </head> <body bgcolor="#000000"> <div align="center"> <table border="0" width="800" cellspacing="0" cellpadding="0"> <tr> <td width="800" bgcolor="#C31325"> <font size="1" color="#C31325"> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="11" align="left" valign="top"> <img border="0" src="images/tlban.jpg" width="11" height="11"></td> <td align="center"><b> <font color="#FFDD00" face="Arial"> <a href="index.html"><font color="#FFDD00">HOME</font></a></font></b></td> <td align="center"> <font color="#C31325"> <b><font face="Arial"> <a href="printing.htm"><font color="#FFDD00">PRINTING</font></a></font></b></td> <td align="center"><b><font face="Arial"> <a href="signs.htm"><font color="#FFDD00">SIGNS</font></a></font></b></td> <td align="center"><b><font face="Arial"> <a href="copies.htm"><font color="#FFDD00">COPIES</font></a></font></b></td> <td align="center"><b> <font face="Arial" color="#FFDD00"> <a href="banners.htm"><font color="#FFDD00">BANNERS</font></a></font></b></td> <td align="center"><b><font face="Arial"> <a href="contact.htm"><font color="#FFDD00">CONTACT</font></a></font></b></td> <td align="center"><font face="Arial"><b> <a href="specials.htm"><font color="#FFDD00">SPECIALS</font></a></b></font></td> <td align="center"><b><font face="Arial"> <a href="links.htm"><font color="#FFDD00">LINKS</font></a></font></b></td> <td width="11" align="right" valign="top"> <img border="0" src="images/trban.jpg" width="11" height="11"></td> </tr> </table> </td> <tr> <td bgcolor="#FFFFFF"> <form name='form1' action='control.php' method='post' onsubmit='return formValidator()'> <p style="margin-bottom: 0"> <img border="0" src="images/maing1.jpg" width="800" height="171"></p> <div align="center"> <table border="0" width="90%" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" align="left"> <p style="margin-top: 0"> </td> </tr> <tr> <td><b><font size="5" color="#C31325"><i>REQUEST FOR QUOTATION</i></font></b><p><font size="5"><b> By Phone at 951.735.6100</b></font></p> <p><font size="5"><b> By Fax at 951.808.8700<br> </b></font></p> </td> <td> <img border="0" src="images/horsemain.jpg" width="300" height="134"><br> </td> </tr> </table> </div> <div align="center"> <table border="0" width="790" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" style="border-left-style: solid; border-left-width: 2px; border-right-style: solid; border-right-width: 2px; border-top-style: solid; border-top-width: 2px"> <blockquote> <font size="5"><b>Online: <u>Place Order & Upload File Now</u> <br> </b></font>Thanks to the convenience of our online file transfer, there's no need to make special trips to our store just to deliver a disk. You can easily send a file from your computer to ours in a matter of minutes. </blockquote> </td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Your Name </td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input name="name" type='text' size="40" id='name'><font color="#C31325">* <font size="2" face="Arial">(*required field)</font></font></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Company:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input type="text" name="Company" size="40"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Phone Number</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input name="Phone_Number" type="text" size="40 "id='Phone_Number'><font color="#C31325">*</font></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Fax Number</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input type="text" name="Fax_Number" size="40"></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Email</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input name="Email" type='text' size="40" id='Email'><font color="#C31325">*</font></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> Additional Details:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <p style="margin-bottom: 0">Please provide information about the file you are sending. <br> Include what application you used to create the file.</p> <p style="margin-top: 0"> <textarea rows="5" name="Additional_Details" cols="55"></textarea></td> </tr> <tr> <td style="border-left-style: solid; border-left-width: 2px" width="130"> File Type:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <font size="3"> <select size="1" name="File_Type"><option value="PC">PC</option> <option value="Macintosh">Macintosh</option> </select></font> </td> </tr> <tr> <td nowrap="nowrap" style="border-left-style: solid; border-left-width: 2px" width="130"> Application Type:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <select size="1" name="App_Type"> <option value="Not Selected">Please Select</option> <option value="Multiple (Compressed)"> Multiple (Compressed)</option> <option value="Acrobat (PDF)">Acrobat (PDF)</option> <option value="CorelDRAW">CorelDRAW</option> <option value="Excel">Excel</option> <option value="Fonts">Fonts</option> <option value="Freehand">Freehand</option> <option value="Illustrator">Illustrator</option> <option value="InDesign">InDesign</option> <option value="Pagemaker">Pagemaker</option> <option value="Photoshop">Photoshop</option> <option value="PowerPoint">PowerPoint</option> <option value="Publisher">Publisher</option> <option value="Word">Word</option> <option value="QuarkXPress">QuarkXPress</option> <option value="Other">Other</option> </select> </td> </tr> <tr> <td nowrap="nowrap" colspan="2" align="center" style="border-left-style: solid; border-left-width: 2px; border-right-style: solid; border-right-width: 2px"> <hr width="90%"></td> </tr> <tr> <td colspan="2" style="border-left-style: solid; border-left-width: 2px; border-right-style: solid; border-right-width: 2px"> <blockquote> <p align="left" style="margin-bottom: 0">Click on the "Browse" button below to select a file(s) on your computer. After you've selected the file, click the "Submit" button below to transfer your file to us. Please use WinZip or other file compression software to compress the file before you send it. </blockquote> </td> </tr> <tr> <td nowrap="nowrap" style="border-left-style: solid; border-left-width: 1px" width="131"> Filename:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input type="hidden" name="MAX_FILE_SIZE" value="9000000" /> <input type="file" name="userfile" size="50" value="90000000" /></td> </tr> <tr> <td nowrap="nowrap" style="border-left-style: solid; border-left-width: 1px" width="131"> File 2:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input type="file" name="Filename2" size="50"></td> </tr> <tr> <td nowrap="nowrap" style="border-left-style: solid; border-left-width: 1px" width="131"> File 3:</td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> <input type="file" name="Filename3" size="50"></td> </tr> <tr> <td nowrap="nowrap" style="border-left-style: solid; border-left-width: 1px" width="131"> </td> <td style="border-right-style: solid; border-right-width: 2px" width="656"> </td> </tr> <tr> <td colspan="2" bgcolor="#FFDD00" style="border-left-style: solid; border-left-width: 2px; border-right-style: solid; border-right-width: 2px; border-bottom-style: solid; border-bottom-width: 2px"> <p align="center"><font size="3"> <input type="submit" value='Submit' style="font-family: Times New Roman; font-size: 12pt; font-weight: bold"></font><input type="reset" value="Reset" name="B2" style="font-family: Times New Roman; font-size: 12pt; font-weight: bold"></td> </tr> </table> </div> </form> </td> </tr> <tr> <td> <p align="center"><font size="1" color="#FFFFFF">My Site © 2008 • All Rights Reserved • </font></td> </tr> </table> </div> </body> </html> ---------------------------------------My control.php code <?php require 'class.phpmailer.php'; if(!move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name'])){ ('file upload error'); } $mail = new PHPMailer(); $mail->From = 'me@mysite.com'; $mail->AddAddress("me@mysite.com","ABC"); $mail->AddAttachment($_FILES['userfile']['name']); $mail->AddAttachment($_FILES['Filename2']['name']); $mail->AddAttachment($_FILES['Filename3']['name']); $mail->Body ='Name: '.$_POST['name']."\n"; $mail->Body .='Company: '.$_POST['Company']."\n"; $mail->Body .='Phone: '.$_POST['Phone_Number']."\n"; $mail->Body .='Fax: '.$_POST['Fax_Number']."\n"; $mail->Body .='Email: '.$_POST['Email']."\n"; $mail->Body .='Details: '.$_POST['Additional_Details']."\n"; $mail->Body .='Type: '.$_POST['File_Type']."\n"; $mail->Body .='App: '.$_POST['App_Type']."\n"; $mail->Subject = "My Order / Quote Request"; if(!$mail->Send()) { header("Location: http://www.mysite.com/error.htm"); "Mailer Error: " . $mail->ErrorInfo; exit; } header("Location: http://www.mysite.com/thankyou.htm"); ?>
|
|
|
|