【问题标题】:node form submit not working in ctools model节点表单提交在 ctools 模型中不起作用
【发布时间】:2015-06-15 12:58:20
【问题描述】:

我创建了一个 ctools 模型来打开具有字段集合的节点表单。 我正在尝试保存表单,它的显示错误。

function bayerkol_callback($ajax) {
if ($ajax) {
  global $user;
ctools_include('ajax');
ctools_include('modal');

$form_state = array(
  'ajax' => TRUE,
  'title' => t('Add Event'),
);

$output = ctools_modal_form_wrapper('bayerkol_form', $form_state);

if (!empty($form_state['ajax_commands'])) {
  $output = $form_state['ajax_commands'];
}

print ajax_render($output);
drupal_exit();
}
else {
return drupal_get_form('event_calendar_node_form');
}
}   

function bayerkol_form($form, $form_state) {
$form = array();
ctools_form_include_file($form_state, drupal_get_path('module', 'node') . '/node.pages.inc');
$form = node_add('event_calendar');
return $form;
} 

请帮帮我。

【问题讨论】:

    标签: drupal-7 drupal-ctools


    【解决方案1】:

    试试我下面的代码,希望这能奏效。

    function bayerkol_callback($ajax) {
      if ($ajax) {
         global $user;
    
         ctools_include('node.pages', 'node', '');
         ctools_include('modal');
         ctools_include('ajax');
    
         $node = (object) array(
             'uid' => $user->uid,
             'name' => (isset($user->name) ? $user->name : ''),
             'type' => 'article',
             'language' => LANGUAGE_NONE,
         );
    
         $form_state = array(
             'ajax' => TRUE,
             'title' => t('Add Event'),
         );
    
         $form_state['build_info']['args'] = array($node);
    
         $output = ctools_modal_form_wrapper('bayerkol_form', $form_state);
    
         // This means the form has been exectued
         if (!empty($form_state['executed'])) {
             $output = array();
             // Close the modal
             $output[] = ctools_modal_command_dismiss();
         }
    
        print ajax_render($output);
        exit;
      }else {
             return drupal_get_form('event_calendar_node_form');
       }
      }
    

    在上面的代码中不需要调用bayerkol_form 函数。确保您的节点形式是正确的示例:对于文章使用 {article_node_form}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 2013-09-22
      • 2012-09-28
      • 2016-04-06
      相关资源
      最近更新 更多