Qwerty
Qwerty

Reputation: 433

Server side validation on multiple step form with AJAX PHP?

I have a multi-step form (4 steps) which has client side validation using jQuery and uses AJAX to process form inputs. On every next button click my JS validation is run.

But client side validation is not good enough. I would like to setup server side validation too.

So I prefer using AJAX to server side validate the form as it allows same UX as client side validation. I would like to use the instructions here: http://fearlessflyer.com/how-to-ajax-validate-forms/

But how can I follow the similar scripts from that post for a multi-step wizard form rather than a simple form?

  1. Should every next button of a step be a post to do server side validation and process field's inline error in the current step?
  2. Or should the form be posted for server side validation at the final confirmation 4th step? How can the relevant form steps with inline errors be shown when validating form fields right at the last step?

I'm using plain PHP on server side without any frameworks.

Upvotes: 1

Views: 1952

Answers (2)

kfinto
kfinto

Reputation: 301

It depends on you. Both solutions seems good for me. However, client-side validation may be enough for a regular user. And if someone wants to mess with your code, then the server-side validation at the end of the process will stop him from doing so. You can then rewind to the first step that may contain errors and display them.

Upvotes: 1

David Yue
David Yue

Reputation: 725

Your POST Request should be at the 4th and final step of the validation. All the steps should already be loaded onto the HTML Page, you can use javascript to show section by section.

You can have "inline" validation using the onblur="" HTML attribute. The function inside is called when the user unfocuses the input box.

For Ex: <input type="text" onblur="validate()">

Upvotes: 1

Related Questions