I have two different views that need to be toggled on a node page. I cannot put these two views together so I have created a form that will basically take the values of the form that I create, and send them as arguments to the view and display the view. I am attempting to do with this ajax. It works fine but the problem is the second time I run the form it does not refresh or update that view.

function photoflight_albums() {
  $output = render(drupal_get_form('photoflight_gallery_form'));
  $output .= "<div id='gallery-ajax-wrapper'>";
  $output .= views_embed_view('gallery', 'default');
  $output .= "</div>";

  return $output;


//Grabs the node titles
function photoflight_gallery_themes(){
    $type = "photo_theme"; 
    $theme_list = array();
    $nodes = node_load_multiple(array(), array('type' => $type)); 
    foreach($nodes as $themes){
        $theme_list[$themes->title] = $themes->title;
    return $theme_list;

//Form calls back to the function above to the gallery-ajax-wrapper div output above function photoflight_gallery_form($form, &$form_state){ $form = array();

  $form['themes'] = array(
    '#type' => 'select',
    '#options' => array(photoflight_gallery_themes()),
    '#ajax' => array(
            'callback' => 'photoflight_simplest_callback',
            'wrapper' => 'gallery-ajax-wrapper',
  return $form;

//Ajax callback
function photoflight_simplest_callback($form, $form_state) {
    $view = views_get_view('gallery');
    $args = array( 'title' => $form_state['values']['themes']);
    $output = $view->preview('default', $args);
    return array("#markup" => $output);


1 Answer 1


The issue was that it was removing the HTML element so the second call had no HTML to replace. Changed to either use ajax update or on the call back wrap the return in the div again

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.