By jorje29 on
It's based on ahah_helper module. In case you want to display a view based on what value you get by an ahah form ( select box ). This value can be passed to the view, as argument.
function standings_form($form_state) {
$form = array();
// Register the form with ahah_helper so we can use it. Also updates
// $form_state['storage'] to ensure it contains the latest values that have
// been entered, even when the form item has temporarily been removed from
// the form. So if a form item *once* had a value, you *always* can retrieve
// it.
ahah_helper_register($form, $form_state);
// Determine the default value of the 'usage' select. When nothing is stored
// in $form_state['storage'] yet, it's the form hasn't been submitted yet,
// thus it's the first time the form is being displayed. Then, we set the
// default to 'company'.
if (!isset($form_state['storage']['groupset']['dropdown'])) {
$group_nid = 1;
}
else {
$group_nid = $form_state['storage']['groupset']['dropdown'];
}
$form['groupset'] = array(
'#type' => 'fieldset',
'#title' => t('Fieldset'),
'#prefix' => '<div id="group-wrapper">', // This is our wrapper div.
'#suffix' => '</div>',
'#tree' => TRUE, // Don't forget to set #tree!
);
$form['groupset']['dropdown'] = array(
'#type' => 'select',
'#title' => t('Group'),
'#options' => array('1' => 'group1', '2' => 'group2', '3' => 'group3' ),
'#default_value' => $group_nid,
'#ahah' => array(
'event' => 'change',
// This is the "magical path". Note that the parameter is an array of
// the parents of the form item of the wrapper div!
'path' => ahah_helper_path(array('groupset')),
'wrapper' => 'group-wrapper',
),
);
$form['groupset']['update'] = array(
'#type' => 'submit',
'#value' => t('Display'),
// Note that we can simply use the generic submit callback provided by the
// ahah_helper module here!
// All it does, is set $form_state['rebuild'] = TRUE.
'#submit' => array('ahah_helper_generic_submit'),
// We set the 'no-js' class, which means this submit button will be hidden
// automatically by Drupal if JS is enabled.
'#attributes' => array('class' => 'no-js'),
'#effect' => 'replace',
);
#display view
//view name
$viewName = 'league_standings';
//pass $group_nid argument to view
$view_content = views_embed_view($viewName, 'default', $group_nid);
$form['groupset']['view'] = array(
'#type' => 'markup',
'#prefix' => '<div>',
'#value' => $view_content,
'#suffix' => '</div>',
);
return $form;
}