All set with jQuery Validation.. now what?

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.

Some background:
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)

Looking for:
A PHP script that will Validate what jQuery Validation sends it, or if JavaScript is disabled, fallback to the next best thing. Considering the majority of folks do have JavaScript enabled I’m guess the next best thing would be a simple “thank you” or “problem submitting email” page with a redirect back to the site. Does that not seem like the better option than converting my entire site over to index.php for the sake of my email form?

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

You don’t necessarily have to use ajax, you can also send the entire form to the PHP script (like a form usually works, its content gets sent to the script identified in the form’s action. Specify the script in the form’s action anyway, even if you use ajax, because that way it’ll work for users with javascript disabled as well.
In the PHP script, you’ll have to repeat any validation you performed with jQuery anyway :wink:

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 :slight_smile:

Jquery validation and Ajax type submit can be very tricky I found. You can make it easier on yourself and iksney the single page form and do it more slandered so it just goes to a thank you page once submitted. I did a pretty damn complete tut on that here http://www.websitecodetutorials.com/code/php/how-to-html-form-with-php-js-captcha-validation.php.

Here is how I did the Ajax submit so there was no page refresh on submit all of the form.http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php. Not the cleanest as there are just simple one page ones but it was the only way I could manage to make it work in combo with jQuery validation.

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. :slight_smile: