Community

Multistep ajax form loosing its ajax behavior when submitted with errors

Hi,

I have created a quite complexe multistep ajax form.
It works pretty well except when some mandatory fields are missing.

Actually, the form is returned correctly with all the errors highlighted. But when I try to submit it again, it is not an ajax form anymore and it returns a json array instead of the next step.

May be it's because at some step, the form id changes:
For example, let's say the form id is "wizard", at some point in the multistep process it becomes "wizard--5".

Any idea why ?

Best regards
Geraud

Comments

Are you using any contributed

Are you using any contributed module for multistep ajax form?
Or it is customized?

If it is customized then there might be event listener issue.
Events might be reset after submitting the form.

-Imran

Thanks for your answer

Thanks for your answer Imran.

It's a 100% customized form (no webform module what so ever).
But I make use of tons of jquery scripts in the form (custom widgets...).

How can I reset events ?

FIXED !!!

I found this discussion:
AJAX form can submit inappropriately to system/ajax after failed validation
http://drupal.org/node/671184

What I did:

1. added $form_state['cache'] = TRUE;

2. in my callback function, passed the old form into drupal_rebuild_form() as the 3rd argument to get the form rebuilt as expected. Then returned:
return drupal_rebuild_form('my_form', $form_state, $form);
instead of the initial array of ajax commands (for fancy ajax effects).

3. Put all my custom ajax commands in a hook:
hook_ajax_render_alter(&$commands)

Hope that will help other drupal 7 ajax developers.

nobody click here