sending data to modal dialog forms
cangeceiro - November 9, 2009 - 16:04
| Project: | Chaos tool suite |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Jump to:
Description
I'm kinda stumped on this, and hoping someone here could offer some insight. Hopefully its a simple question. I am using the ctools modal dialogs to generate some sub forms. The issue i can't get around is how do i send data to the form. In my case I want to auto populate some of the form fields based on criteria on the parent page. But i'm just not figuring this one out.
Thanks in advance

#1
$form_state + hook_form_alter() allows this. For instance, in your callback to generate your form you have something like:
<?php$form_state = array(
'title' => t('Login'),
'ajax' => TRUE,
);
$output = ctools_modal_form_wrapper('user_login', $form_state);
?>
In addition to adding more arguments and data in the form_state at that point, you can do something like this:
<?phpfunction mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_login' && $form_state['ajax']) {
$form['name']['#default_value'] = 'josh';
}
}
?>
Which will allow you to pre-fill the values.