function finder_form in Finder 6
Same name and namespace in other branches
- 7.2 includes/form.inc \finder_form()
- 7 includes/finder.form.inc \finder_form()
FAPI definition for the finder form.
Parameters
&$form_state: The Forms API form state.
$finder: The finder object.
See also
1 string reference to 'finder_form'
- finder_forms in ./
finder.module - Implementation of hook_forms().
File
- includes/
finder.form.inc, line 17 - The finder form.
Code
function finder_form(&$form_state, $finder) {
$form = array();
// see if there is already a form state we should be using.
$finder_form_state = finder_form_state($finder->finder_id);
if (is_array($finder_form_state)) {
$form_state = array_merge($form_state, $finder_form_state);
}
finder_invoke_finderapi($finder, 'finder_form', $form, $form_state);
$form['finder_id'] = array(
'#type' => 'value',
'#value' => $finder->finder_id,
);
$form['#action'] = url($finder->path);
$form['finder_form'] = array(
'#weight' => 0,
'#prefix' => '<div class="finder-form finder-' . $finder->finder_id . '">',
'#suffix' => '</div>',
);
if ($finder->settings['form']['prefix']) {
$form['finder_form']['#prefix'] .= '<div class="prefix">' . check_markup($finder->settings['form']['prefix'], $finder->settings['form']['prefix_format'], FALSE) . '</div>';
}
$max_weight = 0;
foreach ((array) $finder->elements as $element) {
$max_weight = max($max_weight, $element->weight);
if (isset($form_state['values'][$element->finder_element_id])) {
$element_default = $form_state['values'][$element->finder_element_id];
}
else {
$element_default = $element->settings['form']['default_value'];
}
$form['finder_form'][$element->finder_element_id] = array(
'#title' => check_plain($element->title),
'#weight' => $element->weight,
'#description' => check_markup($element->settings['form']['description']),
'#prefix' => check_markup($element->settings['form']['prefix'], $element->settings['form']['prefix_format'], FALSE),
'#suffix' => check_markup($element->settings['form']['suffix'], $element->settings['form']['prefix_format'], FALSE),
'#default_value' => $element_default,
'#required' => $element->settings['form']['required'],
'#executes_submit_callback' => TRUE,
);
$module =& $element->element_handler['#module'];
// module_invoke doesn't seem to handle references.
$handler_function = $module . '_finder_element';
if (function_exists($handler_function)) {
$handler_function($element, $form['finder_form'][$element->finder_element_id]);
}
}
if ($finder->settings['advanced']['submission']) {
$form['finder_form']['submit'] = array(
'#type' => 'submit',
'#name' => 'find',
'#value' => $finder->settings['form']['button_text'],
'#weight' => $max_weight + 1000,
);
if ($finder->settings['advanced']['ahah']) {
$wrapper = $finder->finder_view_build_id;
$ahah_display = 'block';
// Check if the 'ahah_remote' setting is on, that we are on the finder page, and that we are in a block.
if ($finder->settings['advanced']['ahah_remote'] && strpos($_GET['q'], $finder->path) === 0 && $finder->finder_view_build_display === 'block') {
// We are using the block as a remote control for the page. Change the wrapper for AHAH purposes.
$wrapper = 'finder-page-' . $finder->finder_id . '-wrapper';
$ahah_display = 'page';
}
$form['finder_form']['submit']['#ahah'] = array(
'path' => 'finder/finder_ahah/' . $finder->finder_id . '/' . $ahah_display . '/' . urlencode(urlencode($_GET['q'])),
'wrapper' => $wrapper,
'method' => 'replace',
'effect' => $finder->settings['advanced']['ahah_effect'],
);
}
if ($finder->settings['advanced']['goto'] == 'go') {
$form['finder_form']['submit']['#prefix'] = '<div class="finder-buttons">';
$form['finder_form']['go'] = array(
'#type' => 'submit',
'#name' => 'go',
'#value' => $finder->settings['form']['go_text'],
'#weight' => $max_weight + 1010,
'#suffix' => '<br class="finder-clear" style="clear:both;" /></div>',
);
}
}
if ($finder->settings['form']['suffix']) {
$form['finder_form']['#suffix'] = '<div class="suffix">' . check_markup($finder->settings['form']['suffix'], $finder->settings['form']['suffix_format'], FALSE) . '</div>' . $form['finder_form']['#suffix'];
}
$form['#submit'] = array(
'finder_form_submit',
);
$form['#validate'] = array(
'finder_form_validate',
);
return $form;
}