I have an email form set up with jQuery Validation. What’s my best direction from here? I’ve read countless blogs, tutorials, and articles on ajax and PHP forms. It’s starting to feel like information overload. There are just so many options and arguments for the best way to go about it, and I’m lost with PHP as it is.
I have a single page website with a contact form at the bottom (name, email, message).
It is a .html file (I mention this because some sources suggest combining everything e.g. index.php)
I’ve been racking my brain over this for the past week. I’m finally at my breaking point, so I’m reaching out for some direction. This is the last leg of my project, and I set out thinking that web forms are so commonplace, that a simple google search would lead me to awesome-ajax-php-form-that-everyone-uses.php, and that It’d be as easy to install as it is to include jquery to your site. Guess not. hehe
In the PHP script, you’ll have to repeat any validation you performed with jQuery anyway
Yes that sounds completely fine to me. If it’s just the one site I wouldn’t bother with an index.php to route everything, it’s just not worth the hassle. Routing everything though one index.php is very nice for sites with a lot of pages that have a common layout (header, footer, etc), but for one page there is no benefit. Indeed, html is even faster than PHP because you’re webserver doesn’t have up “spin up” the PHP module (Apache will do this anyway, also for serving HTML, but that’s a rant for another day ;))
Anyway, having a PHP script that validates the input (regardless of whether it was validated by jQuery before, PHP doesn’t know that), and then redirects to either a page saying if it was correct not would be the simplest option here, as you say.
One advantage of making the site in PHP though, is that you can highlight any fields that are filled in incorrectly after the user has submitted the page. Something you can’t do with HTML. That is probably more user friendly than just saying “Oops, something went wrong, please go back and try again”, or something along those lines
Sorry for the late response, fellas. Thank you for the feedback. You’ve given me some direction to investigate into. I’ll take a closer look after the holiday weekend. Have a good Thanksgiving to those of you that celebrate.