节点表单提交不在ctools模型中工作

时间:2015-06-15 12:58:21

标签: drupal-7 drupal-ctools

我创建了一个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;
} 

请帮帮我。

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,希望这会有效。

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函数。确保您的节点表单是正确的示例:for article use {article_node_form}