I’m creating a form that is split up into 5 steps.
By the way this is just one form - and not 5 separate forms. I have a continue button on each step, which is just an image button - when you click on the image button it hides the current step and displays the next step.
Now I need to perform AJAX validation on each step. I have read that I can use
$model->validate();
and specify the attributes but how do I do this on each step? As I am not actually submitting the form on each step, how do I make the image button call the validation function?
why not split your form to five subforms? you could set enableAjaxValidation to true for each form
and in last step you could calls an action that save all of models.
In any case you could make five actions (or one with parameter) which accept ajax requests and returns message "success" or specified form with errors (by renderpartial). Then according to the data ("success" or html form) client server (javascript) allows the user to fill the next form or not
So, the solution could be the second option I mentioned. Make five ajax-mode action (or one with paramater) in the same controller. If you have one model you should use scenarios in your model that settle the specific fields for each state as required. In the last scenario you have to settle all the fields as required.
You can set validation on fields according to your requirement on the form that render… so on applying scenario on particular action the validation will be applied.