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

Comments

joshk’s picture

Status: Active » Needs work

$form_state + hook_form_alter() allows this. For instance, in your callback to generate your form you have something like:

  $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:

function 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.

merlinofchaos’s picture

Status: Needs work » Fixed

I think josh's answer sufficiently covers this!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.