By jorje29 on
I have 2 problems with the following form :
1) default value in the select box is always 1;
2) The pre-built view "league_standings" doesn't show up, when form is submitted automatically through onChange trigger. Still, the function "standings_display" is called.
Edit : I see now that if I add drupal_set_message($view_content); ( see the added code below in comments ), it shows my view as expected !!! of course, it's themed like a normal drupal_set_message and it shows up above my select box, so I don't consider it a solution. So the question becomes : why I can't display anything inside "standings_display" function ? very strange...
Any idea ?
#hook_menu
$items['node/%/league_standings']= array(
'title' => t('Standings'),
'page callback' => 'drupal_get_form',
'page arguments' => array('standings_form'),
'access callback' => 'league_check',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
#hook_form
function standings_form($form_state) {
if (!isset($form_state['dropdown'])) {
$group_nid = 1;
}
else {
$group_nid = $form_state['dropdown'];
}
$form['groupset']['dropdown'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => array(
'1' => t('group 1'),
'2' => t('group 2'),
'3' => t('group 3'),
),
'#default_value' => $group_nid,
'#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
'#attributes' => array('onchange' => "form.submit('dropdown')"),
'#weight' => 1,
);
$form['groupset']['group_nid'] = array(
'#type' => 'hidden',
'#value' => $group_nid,
);
$form['groupset']['submit'] = array(
'#type' => 'submit',
'#value' => 'Display',
'#submit' => array('standings_display'),
'#attributes' => array('style' => 'display: none;'),
'#weight' => 2,
);
return $form;
}
#submit_function
function standings_display($form, &$form_state) {
$group_nid = $form_state['values']['group_nid'];
$viewName = 'league_standings';
$view_content = views_embed_view($viewName, 'default', $group_nid);
//drupal_set_message($view_content);
return $view_content;
}