node form submit not working in ctools model

647 views Asked by At

I have created a ctools model to open node form having field collection. I am trying to save form, its show error.

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;
} 

Please help me out.

1

There are 1 answers

0
Samit Khulve On

Try my following code, hope this will works.

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');
   }
  }

In above code no need to call bayerkol_form function. make sure your node form is correct example: for article use {article_node_form}