drupal ctools multi step node form

878 Views Asked by At

I've built a ctools modal form with multi step like this, and I've built a ctools modal node form like this.

Cool! but now I want a ctools multi-step modal node form. Yes, I could render all the fields via Form API, hang all the validation & custom widgets and then write my own submit handler, but why bother when the node form would do that for me already?

Any help would be greatly appreciated.

1

There are 1 best solutions below

0
dotist On

I figured it out. The trick was to load the node into the $form_state as an argument, then there are a couple ways you can render the form (see below).

ctools_include('node.pages', 'node', '');
$form_state['build_info']['args'] = array($node);
$output = ctools_modal_form_wrapper('my_content_type_node_form', $form_state);
print ajax_render($output);

ctools_include('node.pages', 'node', '');
$form_state['build_info']['args'] = array($node);
$form = drupal_retrieve_form('my_content_type_node_form', &$form_state);
print ajax_render($output);

My reason for wanting this was to avoid having to re-include all the submission handlers & validation that the node form already possesses. However due to the ajax, if you have a file upload in your form, you'll also need this:

form_load_include($form_state, 'inc', 'node', 'node.pages');