Skip Client Side Validation On Specific Condition

Hi, i’ve a multipage form, of 3 steps.

For each step i’ve created a controller/Action, in each view of this 3 steps i’ve back and next button.

So when i click next simply submit the form to the next action and trigger the client side validation.

Here the problem: when i click on back button, i want to skip client side validation.

I’ve tried this method but it didn’t work:

  1. Create a hidden field called ‘submitType’ initially filled with the value ‘send’

  2. Declaring back button as simple button (not submit button), when i clic on back, he trigger his own onclick function, that at first set submitType value as ‘back’ and the call submit, in this way




'onclick' => '  $('#submitType').val('back'); $('#myForm').submit();'



  1. Add my custom beforeValidate callback to CActiveForm declaration ->



"beforeValidate" => 


"function (form) { 

  if $('#submitType').val() == 'back') { 

    this.validateOnSubmit = false; 

    form.submit(); 

  }   

}

"



But this method go into a loop :(

If i substitute form.submit() whit “return true” the client side validation start and i don’t want this. I’ve tried also with “return false” and in this case nothing happens.

I haven’t any idea how to solve.

Anyone kwow how to do?

Thank you

Use link instead of button (it can be styled as a button, but still a link)

Mmmm… it seems to be a good idea, i’ll try and let you know. Can i send POST data with link? ( I remember it’s possible).

Does the validation will trigger or not (as i want)?

For the moment i say you thank you :)

Yes, you can, but first you should decide is it really needed (back link is more like a get request, no?)

If post is needed, you can use js onclick handler to create and submit a form.

If you need to post back the same form from step 2 - it’s simpler to use button instead of link. Just modify your form submit/validate handlers slightly to intercept required events and not to fall into recursion.

Yeah is exactly what i’m trying to do, but i don’t know how, can you post some pieces of code?

In the first post of this topic i’ve pasted the code that i’ve used.

I know how to intercept the request, when it’s used pure jQuery, but here, is the yiiactiveform.js that intercept all the request, and i don’t know how to modify to my purpose.

Thanks, with link instead of submit button it works. Also i’ve the possibility to send post and get data at the sime time.

Here the example (look for number 10) : CHtml by example