0

I am creating a registration form it has multiple stages. I am able to redirect to another page with the help of a link. How can i get the form as a popup with a button.

 $form['adding_disease']=array( 
   '#markup'=> '<a href ="nojs">'.t('disease_list').'</a>', 
 );

Here this snippet is written in a form with many other fields. this link is in the middle of the form.

1

Another solution is to use Ctools Automodal module. This approach is less complicated to @Web-Beest answer.

Here is the example on how to use it.

function mymodule_menu() {
  $items['mymodule/form'] = array(
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_form'),
    'access arguments' => array('administer mymodule'),
    'modal' => TRUE, 
  );
}

The most important line in the above code is 'modal' => TRUE,.

0

You can use a CTools Modal window for this.

First you need to add a path to your hook_menu() which will call the modal function.

$items['your_path'] = array(
  'title' => 'Do modal popup',
  'page callback' => 'module_form_modal',
  'type' => MENU_NORMAL_ITEM,
);

Then you can create the function which will do the magic. The 'ctools_modal_form_wrapper' will wrap the form so it can be loaded in the modal.

function module_form_modal() {
  ctools_include('modal');
  ctools_include('ajax');

  $form_state = array(
    'ajax' => TRUE,
    'title' => '',
    'build_info' => array('args' => array()),
  );
  $commands = ctools_modal_form_wrapper('YOUR_FORM_NAME', $form_state);
  if (!empty($form_state['ajax_commands'])) {
    $commands = $form_state['ajax_commands'];
  }
  print ajax_render($commands);
}

Then you need to add a ctools button in your form so it knows to use the modal.

$link = ctools_modal_text_button($text, 'your_path', $alt, $class);
0

this worked for me.

$form['adding_disease']=array(
'#markup'=>'<a  href="path/nojs" class=" ctools-use-modal" >'.t('click here').'</a>'
);

and don't forget to include the below three lines in the callback, before calling the form.

ctools_include('modal');
ctools_modal_add_js();
ctools_include('ajax');

Your Answer

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

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