0

A very strange issue come across while using ctools_modal_form_wrapper and ctools-use-modal. I have written a menu item and passed two arguments in it.

$items['a/b/c/d/e/%/edit/%ctools_js'] = array(
    'page callback' => 'generate_tpls_callback',
    'page arguments' => array(5,7),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'tpl_popup_create.inc'
  );

Now in this callback I am getting both 5th and 7th argument. But when I pass it to $form_state, form is unable to get this 5th argument. I will explain you more with the help of code.

function generate_tpls_callback($cid, $ajax) {
    if ($ajax) {
        ctools_include('ajax');
        ctools_include('modal');

        $form_state = array(
            'ajax' => TRUE,
            'title' => t('Display box to change title'),
            'cid' => $cid,
        );
        $output = ctools_modal_form_wrapper('myform', $form_state);
        if (!empty($form_state['ajax_commands'])) {
            $output = $form_state['ajax_commands'];
        }
        print ajax_render($output);
        drupal_exit();
    } else {
        print_r("helloooo");
//        
    }

}

So, the issue is, when I click a link say "generate tpl" a popup appears that contains form items. I want the above 5th argument appears in this form. i.e. $cid. How can I do this. Please help.

1 Answer 1

3

You must use $form_state to do it.

$form_state['build_info']['args'] = array($node);

function generate_tpls_callback($cid, $ajax) {
    if ($ajax) {
        ctools_include('ajax');
        ctools_include('modal');

        $form_state = array(
            'ajax' => TRUE,
            'title' => t('Display box to change title'),
            'cid' => $cid,
        );
        $form_state['build_info']['args'] = array($myvar);  //Check form below
        $output = ctools_modal_form_wrapper('myform', $form_state);
        if (!empty($form_state['ajax_commands'])) {
            $output = $form_state['ajax_commands'];
        }
        print ajax_render($output);
        drupal_exit();
    } else {
    }

}

function myform($form, &$form_state, $myvar) {
...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.