I simply want to remove the redirect on ajax saves. This question is recurring i know.... and i've researched and tested the advised approach but I must be doing something wrong.
I'm putting in my theme template.php:

function MYTHEMENAME_asaf_form_ajax_commands_alter(&$commands, $form, &$form_state, $form_id) {
    $commands[] = ajax_command_remove('asafRedirect');
    return array(
        'command' => 'remove',
        'selector' => $commands,
    );
}

I'm clearly not understanding how to remove the command... can you help?

Comments

taldy’s picture

Hello apmsooner,

You should try something like this:

function MYTHEMENAME_asaf_form_ajax_commands_alter(&$commands, $form, &$form_state, $form_id) {
  foreach($commands as $key => $command) {
    if ($command['command'] == 'asafRedirect') {
      unset($commands[$key]);
      break;
    }
  }
}

I can't run and test it now because I'm writing from my phone, but this code should work :)

apmsooner’s picture

Thanks so much for the reply. I modified my code and cleared the cache however.... still redirecting. I'd sure appreciate a followup with code that will work when you get a chance.

Would help if i put the code in the right template! Your code works great. Thank you so much!

apmsooner’s picture

Status: Active » Closed (fixed)
W.M.’s picture

Is the information here (at comment #1) still valid?

I am trying to use the hook under omega and tej themes but failing.

I basically need to refresh a view inside one page at my site after submitting a node add form using ASAF. The add node form and the view are both on same page. I want to update the view without the need to reload the page after Ajax form submit. I think ajax commands is the way to go.

Any help would be highly appreciated.

apmsooner’s picture

I provided complete example here: https://www.drupal.org/node/2301041

Try with that code and see if it helps

candelas’s picture

Thanks @taldy your example still works :)