ctools_build_form
- 6
ctools_build_form($form_id, &$form_state)
Build a form, similar to drupal_get_form(). However, arguments
to the form builder are not sent through. Instead, the $form_state
can be given all the necessary data to fully utilize the form.
Code
contributions/ctools/includes/form.inc, line 21
<?php
function ctools_build_form($form_id, &$form_state) {
$form_state += array('storage' => NULL, 'submitted' => FALSE, 'input' => $_POST, 'method' => 'post');
$args = isset($form_state['args']) ? $form_state['args'] : array();
$cacheable = FALSE;
if (isset($_SESSION['batch_form_state'])) {
$form_state = $_SESSION['batch_form_state'];
unset($_SESSION['batch_form_state']);
}
else {
if (isset($_POST['form_id']) && $_POST['form_id'] == $form_id && !empty($_POST['form_build_id'])) {
$form = form_get_cache($_POST['form_build_id'], $form_state);
if (!empty($form['#no_cache']) || empty($form)) {
unset($form);
}
}
if (!isset($form)) {
$form_state['post'] = $form_state['input'];
if (isset($form_state['wrapper callback']) && function_exists($form_state['wrapper callback'])) {
$form = array();
$form_state['wrapper callback']($form, $form_state);
if (function_exists($form_id)) {
$form_id($form, $form_state);
}
}
else {
$args_temp = $args;
array_unshift($args_temp, 'placeholder');
$args_temp[0] = &$form_state; array_unshift($args_temp, $form_id);
$form = call_user_func_array('drupal_retrieve_form', $args_temp);
}
$form_build_id = 'form-' . md5(mt_rand());
$form['#build_id'] = $form_build_id;
if ($form_state['method'] == 'get' && !isset($form['#method'])) {
$form['#method'] = 'get';
}
drupal_prepare_form($form_id, $form, $form_state);
$original_form = $form;
$cacheable = TRUE;
unset($form_state['post']);
}
$form['#post'] = $form_state['input'];
ctools_process_form($form_id, $form, $form_state);
if (!empty($form_state['executed']) && empty($form_state['rerender'])) {
return;
}
if ($cacheable && !empty($form['#cache']) && empty($form['#no_cache'])) {
form_set_cache($form_build_id, $original_form, NULL);
}
}
if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {
$form = ctools_rebuild_form($form_id, $form_state, $args);
}
if (!empty($form_state['want form'])) {
return $form;
}
if (!empty($form_state['drop tokens'])) {
unset($form['#id']);
unset($form['#build_id']);
unset($form['#token']);
unset($form['form_token']);
}
if (!empty($form_state['drop tokens'])) {
unset($form['form_id']);
unset($form['form_build_id']);
unset($form['form_token']);
}
return drupal_render_form($form_id, $form);
}
?>