0

this code work but the views is callback only once (reload only once), any idea to reload more than one time ?

see in detail on drupal.org

function modulename_form_alter (&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'form_id_of_your_afb_form':
            $form['#validate'] = array();
            $form['ajax-submit']['#ajax']['callback'] = 'modulename_create_callback';
    }
} 
function modulename_create_callback($form, &$form_state) {
    // load view
    $view1 = views_embed_view('view_name','view_display_name',$view_arguments_as_required);

    // replace the afb form with a clean form
    $newform = afb_ajax_handler($form, $form_state);
    $commands = array(
      ajax_command_replace('#target_div_id_of_view_to_update .view',$view1),
      ajax_command_replace('#target_div_id_of_afb_form_to_replace',render($newform)),
    );
    $form['#type'] = 'ajax';
    $form['#commands'] = $commands;
    return $form;
}
1

According to your description and code you have only one requirement that is update views block on form submission. So,

  • You don't have to alter the form AJAX as AFB form submission already uses AJAX.
  • Furthermore, you don't have to replace the form using ajax_command_replace() as its already replacing using AFB
  • You don't have even to return the form as well.

What do you need is to

So, use below code to get it worked.

function MODULENAME_form_alter (&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'sport_node_form':
            if ($term = menu_get_object('taxonomy_term', 2)) $_SESSION['tid'] = $term->tid;
    }
}
function MODULENAME_ajax_render_alter(&$commands) {
    if(isset($_SESSION['tid']) && is_numeric($_SESSION['tid'])){
        $mavue_new = render(views_embed_view('mavue_new','default', $_SESSION['tid']));
        $commands[] = ajax_command_replace('.view-mavue-new', $mavue_new);
    }
}

I hope this would help someone else.

1

you just need to put the number of tid directly here :

ajax_command_replace('#target_div_id_of_view_to_update .view','1'),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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