Hiya,
I made this script years ago, and now don't understand what is happening.
I wondered if someone would be so kind as to recode it using proper variable names etc instead of just using names like $k and $p (I know these names are bad, and I no longer do this. But like I said it was a long time ago since I coded this).
Also, how do you output the appropriate error messages next to the correct field within the form?
Is there a better way of doing this?
Code:<?php $post = array("name" => "", "email" => "", "phone" => ""); $errors = $post; if (isset($_POST["submit"])) { foreach ($post as $k => $v) $post[$k] = stripslashes($_POST[$k]); if ($post["name"] == "") $errors["name"] = "error"; if (!preg_match('/[^@]+@[^.]+(\.[^.]+)+/', $post["email"])) $errors["email"] = "error"; if ($post["phone"] == "") $errors["phone"] = "error"; $error = false; foreach($errors as $k => $v) { if ($errors[$k] != "") $error = true; } if (!$error) { $message = ""; foreach($post as $k => $v) if ($v != "") $message .= "$k: $v\n"; $sent = mail("info@company.com", "Subject", $message, "From: info@company.com"); } } ?> <form name="form" method="post" action=""> SECTION #1<br> <br> Name: <input name="name" type="text" id="name"> <br> <br> E-Mail: <input name="email" type="text" id="email"> <br> <br> Phone: <input name="phone" type="text" id="phone"> <br> <br> <input name="send" type="submit" id="send" value="Send"> <input name="reset" type="reset" id="reset" value="Reset"> </form>



).




Bookmarks