Hi, I am using a contact form here: http://www.mindreality.com/contact.html It uses the formmail code. What is the code that I can include to check whether user has entered an email address in the email field, and also to check whether it is the correct format?
This should do it: if (!filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { echo 'Invalid email address'; } Code (markup): where the "$contact_email" is the submitted email address
Where do I put that code? This is my entire html code for that page: <body style="text-align: center"> <h1 align="left"><font face="Times New Roman" size="7">Contact</font></h1> <p align="left"><font face="Arial" size="2"><strong>Hello Friend,</strong> </font> </p> <p align="left"><font face="Arial" size="2">Here is where you can tell me your testimonials, suggestions or questions!</font></p> <p align="left"><font face="Arial" size="2">Regards,</font></p> <p align="left"><font face="Arial" size="2">Enoch Tan - Creator of Mind Reality</font></p> <form action="http://www.mindreality.com/cgi-sys/formmail.pl" method="post"> <input type="hidden" value="email@email.com" name="recipient"> <input type="hidden" value="Message to Mind Reality" name="subject"> <table cellSpacing="10" cellPadding="0" width="600" border="0"> <tr> <td vAlign="top" align="right"> <p align="center"><font face="arial" size="-1"><b>Your Name:</b></font><br> <input size="25" name="Name"> </td> <td vAlign="top" align="left"> <p align="center"><font face="arial" size="-1"><b>Your Email:</b></font><br> <input size="25" name="Email"> </td> </tr> <tr> <td colSpan="2"> <p align="center"> </td> </tr> <tr> <td vAlign="top" align="right"> <p align="center"><font face="arial" size="-1"><strong>Would you visit this web site again?</strong> (optional)<br> Yes<input type="radio" value="Yes, I would visit again" name="Visit"> No<input type="radio" value="No, I wouldn't visit again" name="Visit"> </font></td> <td vAlign="top"> <p align="center"><font face="arial" size="-1"><strong>How did you hear about my site?</strong> (optional)<br> <input type="radio" value="A popular search engine" name="Hear About">A popular search engine (what keywords?)<br> <input type="radio" value="Link from another site" name="Hear About">Link from another site (tell me which site)<br> <input type="radio" value="From a friend" name="Hear About">From a friend (who?)</font></td> </tr> <tr> <td colSpan="2"> <p align="center"> </td> </tr> <tr> <td vAlign="top" align="middle" colSpan="2"><font face="arial" size="-1"> <b>Write your message here: </b></font><br> <textarea name="Comments" rows="20" cols="60"></textarea> <p><input type="submit" value="Send"></td> </tr> </table> <p> <input type="hidden" value="http://www.mindreality.com/thank-you.html" name="redirect"> </p> <p align="center"><strong><font color="red" face="Arial" size="2">Check carefully that your email is spelt/spelled correctly!</font></strong></p> </form> Code (markup):
The example i gave you is for php, i just noticed you are submitting the form to "formmail.pl" which is a perl file, which i have never worked with so im not sure.