| 6 modal.inc | ctools_modal_form_wrapper($form_id, &$form_state) |
| 7 modal.inc | ctools_modal_form_wrapper($form_id, &$form_state) |
Wrap a form so that we can use it properly with AJAX. Essentially if the form wishes to render, it automatically does that, otherwise it returns so we can see submission results.
The output of the form, if it was rendered. If $form_state['ajax'] is set, this will use ctools_modal_form_render so it will be a $command object suitable for ajax_render already.
The return will be NULL if the form was successfully submitted unless you specifically set re_render = TRUE. If ajax is set the form will never be redirected.
<?php
function ctools_modal_form_wrapper($form_id, &$form_state) {
// This won't override settings already in.
$form_state += array(
're_render' => FALSE,
'no_redirect' => !empty($form_state['ajax']),
);
$output = drupal_build_form($form_id, $form_state);
if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
return ctools_modal_form_render($form_state, $output);
}
return $output;
}
?>