1

I have node creation form in a popup dialog box. I decided to give it a try using ctools modal window. But I seem to be getting errors when I upload an image into a image field after using browse to select it.

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in drupal_retrieve_form() (line 795 of /var/www/html/test/includes/form.inc).
Notice: Undefined index: #node in comment_form_node_form_alter() (line 1193 of /var/www/html/test/modules/comment/comment.module).
Notice: Trying to get property of non-object in comment_form_node_form_alter() (line 1210 of /var/www/html/test/modules/comment/comment.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 629 of /var/www/html/test/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 629 of /var/www/html/test/modules/menu/menu.module).
Notice: Undefined index: #node in menu_form_node_form_alter() (line 630 of /var/www/html/test/modules/menu/menu.module).
Notice: Trying to get property of non-object in menu_form_node_form_alter() (line 630 of /var/www/html/test/modules/menu/menu.module).
Notice: Undefined index: field_artwork_image in file_ajax_upload() (line 271 of /var/www/html/test/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /var/www/html/test/modules/file/file.module)

Below is my code

function portfolio_cust_node_add_modal_callback($js = FALSE) {
  global $user;

  //If people are not using JS. I just tell them "sorry" it is '2012'
  if (!$js) return "Javascript required";
  ctools_include('node.pages', 'node', '');
  ctools_include('modal');
  ctools_include('ajax');

 // Create a blank node object here.
  $node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => 'psuedo_portfolio',
    'language' => LANGUAGE_NONE,
    );

  $form_state = array(
    'title' => t('Add Portfolio'),
    'ajax' => TRUE,
  );
  $form_state['build_info']['args'] = array($node);
  drupal_add_library('system', 'ui.dialog');
  // change this to your type node form
  $output = ctools_modal_form_wrapper('psuedo_portfolio_node_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;

}

I am planning to use colorbox module or some other method which uses a iframe instead of how ctools implements the modal dialog.

Any help will be greatly appreciated.

2 Answers 2

4

I faced the same problem, and I managed to solve it using merlinofchaos's suggestion. I used form_load_include() just after form_state initialization:

  $form_state = array(
    'title' => t('Add new deal'),
    'ajax' => TRUE,
    'node' => $node,
  );

  $form_state['build_info']['args'] = isset($form_state['build_info']['args']) ? $form_state['build_info']['args'] : array($node);
  form_load_include($form_state, 'inc', 'node', 'node.pages');
1
  • I used overlay paths which uses iframe. However this is also working thanks!! will use it the next time.
    – char_x0r
    Commented Sep 4, 2012 at 7:43
0

this fixed for me:

http://drupal.org/node/1336212#comment-6049694

Add the following lines to a hook_menu_alter() implementation:

$items['file/ajax']['file'] = 'node.pages.inc';
$items['file/ajax']['file path'] = drupal_get_path('module', 'node');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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