1

我正在使用 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 函数显示成功消息或失败消息。有什么方法可以使用模态或在称为模态的原始页面上显示输出。

4

2 回答 2

0

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

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

正是我需要的。谢谢。

于 2014-09-17T18:53:04.327 回答
0

调用 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']

此外,如果您使用 actools_ajax_command_reload()这将重新加载模式的内容,并且应该解决另一个 ajax 输出的问题。

于 2014-07-23T12:03:34.513 回答