I have a custom form, on submission of which I am calling ctools modal with a node form(content type: turn).

Code for Custom Form.

function _my_module_name_files_listing_form($form, &$form_state) {
  $form = array();
  $form_state['storage']['values'] = $files;
  $form['download_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Download'),
    '#submit' => array('_my_module_name_files_download_submit'),
  $form['create_segment'] = array(
    '#type' => 'submit',
    '#value' => t('Create Segment'),
    '#attributes' => array('class' => array('ctools-use-modal')),
    '#ajax' => array(
      'callback' => '_my_module_name_files_create_segment',
  $form['upload_content'] = array(
    '#type' => 'submit',
    '#value' => t('Upload Content'),
    '#submit' => array('_my_module_name_files_upload_content'),
  $form['delete_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#submit' => array('_my_module_name_files_delete_submit'),
  return $form;

Callback code for ajax submission rendering node form.

function _my_module_name_files_create_segment($form, &$form_state) {
  global $user;
  $form_id = 'turn_node_form';
  ctools_include('node.pages', 'node', '');
  $destination = 'node/1';
  $form_state = array(
    'ajax' => TRUE,
    'title' => t('Form Title'),
  $node = (object) array(
        'uid' => $user->uid,
        'name' => (isset($user->name) ? $user->name : ''),
        'type' => 'turn',
        'language' => LANGUAGE_NONE,
        'status' => TRUE,

  $form_state['build_info']['args'] = array($node);
  $output = ctools_modal_form_wrapper($form_id, $form_state);
  if (!empty($form_state['ajax_commands'])) {
    $output = $form_state['ajax_commands'];
  if (!empty($form_state['executed'])) {
    $output = array();
    // Redirect to destination.
    $output[] = ctools_ajax_command_redirect('node/8', 0);
  print ajax_render($output);

Problem: Node Form is coming fine on modal and hitting save button triggers ajax call but node form does not submit. Am I missing something here?

  • I'm created a node form in a ctools modal and the code I used looks a lot like yours. I don't see anything wrong with it. I wonder if the form on the parent page that launches the ctools modal is getting in the way? It might be worth launching the node form with a link instead of a form and see if that works. – Evil E Sep 11 '14 at 15:22
  • I thought of keeping it as link instead of submit button but I need submitted values from parent form. – arpitr Sep 11 '14 at 15:53

Try replacing

ctools_include('node.pages', 'node', '');


ctools_form_include_file($form_state, drupal_get_path('module', 'node') . '/node.pages.inc');

It's possible that the node.pages.inc file isn't loaded if the form is found from cached data.

  • I tried, but it's not working – arpitr Oct 7 '14 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.