Drupal Ctools模态处理

时间:2014-02-07 17:35:12

标签: drupal-7 drupal-modules drupal-ctools

我正在使用URL http://mywebsite.org/param/ajax?ID=2调用一个函数,该函数将在html中返回一个表单,我在自定义模块中的Corresponfin回调函数中使用了以下函数。

$form_state = array(
  'ajax' => TRUE,
  'title' => t("Edit : $ID"),
);
$output = ctools_modal_form_wrapper('form_fn', $form_state);
print ajax_render($output);
drupal_exit();

我使用此输出在twitter bootstrap模式中创建一个表单。问题是,当我提交时,我再次得到一个ajax输出,我无法处理。我想基于form_submit函数显示成功消息或失败。有什么方法可以使用模态或在调用模态的原始页面上显示输出。

2 个答案:

答案 0 :(得分:0)

调用ctools模态应如下所示:

  $output = ctools_modal_form_wrapper($form_name, $form_state);
  if(!empty($form_state['executed'])) {
    $output = array();
    $output[] = ctools_modal_command_display(t('Successful message title'), 'Successful message body');
    $output[] = ctools_ajax_command_reload();
  }
  print ajax_render($output);
  exit;

不要忘记检查$form_state['executed']

此外,如果您使用ctools_ajax_command_reload(),这将重新加载模态的内容,并应修复另一个ajax输出的问题。

答案 1 :(得分:0)

请求sirBlond,但我的名声还没有。我在成功提交表单时我的模态窗口没有在IE8中关闭的情况下使用了这个。我需要在重定向之前添加此权限。

$commands[] = ctools_ajax_command_reload()     
$commands[] = ctools_ajax_command_redirect($path, 0, $options);

正是我所需要的。感谢。