lilibirdy Posted January 6, 2009 Share Posted January 6, 2009 Hey. I'm a true novice. Web designer by day, i'm doing a website for myself now (finally) which means i've turned developer overnight and i'm way out of my comfort zone. It's a very simple contact form - here's the code: <?php $myemail = ""; $subject = "Website Enquiry"; $yourname = check_input($_POST['yourname']); $email = check_input($_POST['email'],"Enter your Email address"); $phone = check_input($_POST['phone']); $howcontact = check_input($_POST['howcontact']); $enquiry = check_input($_POST['enquiry']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("Email address not valid"); } $message = "New Enquiry: Name: $yourname Email Address: $email Phone Number: $phone Contact By: $howcontact Enquiry: $enquiry "; mail($myemail, $subject, $message); header('Location: thanks.html'); exit(); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> <a href="/fripperies_contact.html">back to contact form</a> </body> </html> <?php exit(); } ?> This works, but it doesn't work exactly how i'd like it to since it's essentially a cobbled together first attempt. Currently if there's an error you're directed to a new page. Instead, I'd like the error to be highlighted in the form page, with the other fields retaining the text already input. I searched until the wee small hours of the morning for some answers, and found nothing I could get my head around. If someone doesn't mind helping me out i'd be so grateful! Thankyou!!! Link to comment https://forums.phpfreaks.com/topic/139737-can-someone-take-a-look-at-my-contact-form-newbie-big-apologies/ Share on other sites More sharing options...
l_kris06 Posted January 6, 2009 Share Posted January 6, 2009 you are here too Link to comment https://forums.phpfreaks.com/topic/139737-can-someone-take-a-look-at-my-contact-form-newbie-big-apologies/#findComment-731100 Share on other sites More sharing options...
lilibirdy Posted January 6, 2009 Author Share Posted January 6, 2009 lol, i'm everywhere! Link to comment https://forums.phpfreaks.com/topic/139737-can-someone-take-a-look-at-my-contact-form-newbie-big-apologies/#findComment-731103 Share on other sites More sharing options...
bubbasheeko Posted January 6, 2009 Share Posted January 6, 2009 Could you include your contact form as well? Link to comment https://forums.phpfreaks.com/topic/139737-can-someone-take-a-look-at-my-contact-form-newbie-big-apologies/#findComment-731106 Share on other sites More sharing options...
lilibirdy Posted January 6, 2009 Author Share Posted January 6, 2009 <form action="contact.php" method="post"> <p><b>Your Name:</b> <input type="text" name="yourname" /><br /> <b>E-mail:</b> <input type="text" name="email" /><br /> Contact Number: <input type="text" name="phone"></p> <p>How would you prefer us to contact you? <input type="radio" name="howcontact" value="email" checked="checked" /> Email <input type="radio" name="howcontact" value="phone" /> phone <input type="radio" name="howcontact" value="either" /> either</p> <p><b>Your Enquiry:</b><br /> <textarea name="enquiry" rows="10" cols="40"></textarea></p> <p><input type="submit" value="Send it!"></p> <input name="reset" type="reset" value="Reset Form"> <input type="text" name='keepinginfo' id="keepinginfo" <?php if(isset($_SESSION['keepinginfo']){?> value='<?php echo $_SESSION['keepinginfo'];?>'<?php }?> /> </form> Link to comment https://forums.phpfreaks.com/topic/139737-can-someone-take-a-look-at-my-contact-form-newbie-big-apologies/#findComment-731107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.