Jump to content

rb3883

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rb3883's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Tough love huh?? Right, I got rid of that messy table lay out and this appears to work okay, although i'd be extremely grateful if you'd give me your thoughts again? I'll then replicate this for my other 'contact form' fields (Name and Message) although slightly different validation will take place. Thanks a lot for your help, Ryan CODE <?php // shortform.php $fail = $email = ""; $to = 'myemail@address.co.uk'; $subject = 'Contact form email'; $message = 'please work!'; if (isset($_POST['email'])) $email = fix_string($_POST['email']); $fail = validate_email($email); echo "<html><head><title>Shortform</title>"; if ($fail =="") { echo "</head><body>$email successfully validated: .</body></html>"; mail($to, $subject, $message, "From: $email"); exit; } if ((isset($_POST["Submitted"])) && ($fail !="")) { echo <<<_END Sorry, the follwoing errors were found<br /> in your form - $fail<br /> _END; } echo <<<_END <form method="post" action="shortform2.php" onSubmit="return validate(this)"> Email: <input name='email' type="text" value=$email><br /> <input type="submit" value="Submit" /> <input type="hidden" name="Submitted" value="Yes"/> </form> _END; function validate_email($email) { if ($email == "") return "No Email was entered<br />"; else if (!((strpos($email, ".") > 0) && (strpos($email, "@") > 0)) || preg_match("/[^a-zA-Z0-9.@_-]/", $email)) return "The Email address is invalid<br />"; return ""; } function fix_string($string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return htmlentities ($string); } ?>
  2. Thx GingerRobot, so i'm actually almost there?
  3. Hi, i'm a PHP newbie and am working on a contact form which is below. I've just included one field (email) to make things shorter. In practice this works okay but when the page is first displayed it shows the "No Email was entered" error. I know that I need to include something like "if (isset($_POST['submit'])) is true then process the error checking otherwise display the form however I can't seem to find where to put it and spent all weekend on this now, little help? Once i've got this sorted i'll add the other fields and javascript error checking as well. Many thanks Ryan <?php // shortform.php $email = ""; $to = 'myemail@address.co.uk'; $subject = 'Contact form email'; $message = 'please work!'; if (isset($_POST['email'])) $email = fix_string($_POST['email']); $fail = validate_email($email); echo "<html><head><title>Shortform</title>"; if ($fail =="") { echo "</head><body>$email successfully validated: .</body></html>"; mail($to, $subject, $message, "From: $email"); exit; } echo <<<_END <table class="contactform" border="0" cellpadding="2" cellspacing="5" bgcolor="#eeeeee"> <th colspan="2" align="center">contactform</th> <tr><td colspan="2">Sorry, the following errors were found<br /> in your form: <p><font color=red size=1><i>$fail</i></font></p> </td></tr> <form method="post" action="shortform.php" onSubmit="return validate(this)"> <tr><td>Email</td><td><input type="text" maxlength="64" name="email" value="$email" /></td> </tr><tr><td colspan="2" align="center"> <input type="submit" value="Submit" /></td> </tr></form></table> _END; function validate_email($field) { if ($field == "") return "No Email was entered<br />"; else if (!((strpos($field, ".") > 0) && (strpos($field, "@") > 0)) || preg_match("/[^a-zA-Z0-9.@_-]/", $field)) return "The Email address is invalid<br />"; return ""; } function fix_string($string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return htmlentities ($string); } ?> 17567_.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.