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
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.
No because the last step needs to do a normal post request and save all fields to the database. That’s why it needs to be one form.
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.
How do I make it return / display validation messages if I use my own ajax methods?
Basically I want to use the built-in functionality as much as I can rather than duplicating it.
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.
And displaying validation message you can you setFlash() and getFlash() method for displaying your custom message.