0

I added a drupal ajax element to my multistep form but when it runs, it reloads the entire form.

The problem is, there is logic which is performed via a case structure for each step. When the ajax loads, the next step's logic is ran.

For example, the user is on step 2 of a 4 step form.

The user will cause an ajax call to load in a preview image. Triggering this ajax call loads step 3.

Triggering the same ajax call again will submit the form (step 4) causing very undesirable results. Is there some sort of secret voo doo code or argument I can use to prevent this?

1 Answer 1

0

The ajax call has a callback function that has a few commands including what it needs to render again. In this care i image it starts rendering the whole form again. You will see someting like this in the callback.

$commands[] = ajax_command_replace('#form', drupal_render($form));

And you want something like this

$commands[] = ajax_command_replace('#form .ajax-section', drupal_render($form['ajax section']));
4
  • Hey Frogger. Thanks for the help! I'm trying to do it that way, but I'm running into a problem when I try to ajax_deliver the $commands array. Sep 23, 2013 at 20:11
  • I get a parse error with the response. I wish I could paste code in here... Sep 23, 2013 at 20:11
  • 1
    Pastebin Sep 23, 2013 at 20:14
  • what do you get? When your done building the command you deliver it like this return array('#type' => 'ajax', '#commands' => $commands);
    – DD dev
    Sep 23, 2013 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.