【问题标题】:Drupal Ctools Modal HandlingDrupal Ctools 模态处理
【发布时间】:2014-02-07 17:35:11
【问题描述】:

我正在使用 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 引导模式中创建一个表单。问题是当我提交时,我再次得到一个我无法处理的 ajax 输出。我想根据 form_submit 函数显示成功消息或失败消息。有什么方法可以使用模态或在称为模态的原始页面上显示输出。

【问题讨论】:

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


    【解决方案1】:

    调用 ctools modal 应该如下所示:

      $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 输出来解决问题。

    【讨论】:

      【解决方案2】:

      会支持sirBlond,但我的声誉还没有达到。我在成功提交表单后我的模式窗口在 IE8 中没有关闭的情况下使用了这个。我需要在重定向之前添加它。

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

      正是我需要的。谢谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-09
        • 1970-01-01
        • 1970-01-01
        • 2012-04-05
        相关资源
        最近更新 更多