3

Let's say I have a Drupal form with a "Open popup" button and a text field. If user clicks on the button, I'd like to open ctools modal popup with two buttons (#3 and #4). Clicking on any button in the popup should close it and set a text value in a form (i.e. button #3/button #4 was clicked). What's the proper way to implement this functionality?

I know how to open a popup:

$form['popup_result'] = array(
  '#type' => 'textfield', 
  '#title' => t('Subject'), 
  '#default_value' => $node->title, 
  '#size' => 60, 
  '#maxlength' => 128, 
  '#required' => TRUE,
);    

$form['popup_button'] = array(
  '#prefix' => '<div id="popup"></div>',
  '#type' => 'button', 
  '#value' => t('Open popup'), 
  '#weight' => 3,
  '#ajax' => array(
    'wrapper' => 'popup',
    'callback' => 'mymodule_popup_function'
  )
);

and how to set a popup contents:

function mymodule_popup_function($form, &$form_state) {
  ctools_include('modal');
  ctools_include('ajax');
  ctools_modal_add_js();

  $commands = array();  
  $commands[] = ctools_modal_command_display('Title', 'Contents');
  print ajax_render($commands);
  exit;
}

but I have no idea how to render buttons in the popup and populate a value in popup_result textfield.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.