last day (15 days later) » 

5:20 PM
0
A: I need to add required form fields to my contact form but not sure about how to do it?

tdlmIn general, you should be escaping any input from the browser to prevent bad things from happening if you're going to ever display it in a browser or save it to a database. Before the the following line: if(mail($to, $subject, $body, $headers)){ You would need to add some validation to the fo...

 
How would I change the last part to check for errors? I think I understood everything else. Trying it out now, Thanks!
Yes that is exactly what I think I want!
This way works for me except it doesn't keep whats in the form fields when the viewer clicks the button if there are errors?
@tdlm
[benlevywebdesign.com](http://benlevywebdesign.com) If you look at my site and notice the form is at the bottom and when you click submit it sends and shows the confirmation or error message but it goes back to the top of the page and you don't know that it is there unless you scroll back down. How can I get it to submit and go back to the bottom of the page?
 
@benlevywebdesign I updated my answer based on your comments here. Let me know whether that helps!
 
Yes I will try that out
And yes it does work. Thank you so much you just saved me from hours of searching again on the web for an answer that might not have worked! Thank you!
@tdlm last question, how do I get it to remember what was put in the form if I don't go the jQuery Validation route. so if you click on benlevywebdesign.com/#myAnchor7 and just fill out your name and then click send it refreshes with errors saying fill out your email and message but the name space is blank again. someone smart would fill it out again but it would be nice to have it not go away on refresh. does that make sense?
 
@benlevywebdesign, if you have it validate using jQuery, then the text values should not disappear. If you go with PHP POST validation, however, you'd just have to echo the variables into the input values like so:

<input type="text" name="name" id="name" size="30" value="<?php echo isset($name) ? $name : ""; ?>" />
 
@tdlm I don't know how to go about using the jQuery validation just yet because my form is php and the examples I have seen don't have php. Where would I put the lines of code for the post validation method? Thanks for all the help!
@tdlm If I go the jQuery validation route I don't need the other lines of code for the php that you helped me with do I?
 
5:20 PM
@benlevywebdesign, if you want to go the PHP way, here is sample working form.php (pastebin.com/YQVmkWsi) and here is contactform.php (pastebin.com/4rHDrtVi). I tested these on my local and they display errors right above the form as intended. However, if you do use jQuery validation you would not need the other lines of code, no. If you did that, the person would stay looking at the form while errors appeared. How you implement it is really up to you. :)
 
Thank you! My forms have been working all along so I am just trying to get it set up to validate and now I think I have it working!
 
hey Ben
i know they work
but just wanted to clarify that you could do it either way
 
Thanks!
 
brb
 
I know we shouldn't rely on dreamweaver previews of our pages but I get this weirdness happening i.imgur.com/NpkHK.png
It doesn't show up on the web at benlevywebdesign.com/#myAnchor7 but it is just weird?
never mind that I fixed it myself
 
 
2 hours later…
7:30 PM
how would I code in php if lets say they didn't fill in an optional form and I want the email I get to say none in the place of just blank?
 

last day (15 days later) »