Posted by Merlin on Fri, 09/04/2009 - 1:27am
Slides: http://www.slideshare.net/merlinofchaos/the-chaos-tools-suite
This is the modal test module. You can create the .info file that goes with it.
<?php
/**
* Implementation of hook_menu().
*/
function modal_test_menu() {
$items = array();
$items['modal_test'] = array(
'title' => 'Modal test',
'access callback' => TRUE,
'page callback' => 'modal_test_page',
);
$items['modal_test/form'] = array(
'title' => 'AJAX modal dialog',
'access callback' => TRUE,
'page callback' => 'modal_test_popup',
'type' => MENU_CALLBACK,
);
return $items;
}
function modal_test_page() {
ctools_include('ajax'); // Module include the dependence it needs for ajax.
ctools_include('modal');
ctools_modal_add_js();
$output = ctools_modal_text_button(t('Click Here'), 'modal_test/form', t('Pop me up'));
$output .= '<div id="modal-message"> </div>';
ctools_include('plugins');
return $output;
}
function modal_test_popup() {
ctools_include('ajax');
ctools_include('modal');
$form_state = array('ajax' => TRUE);
$output = ctools_modal_form_wrapper('module_test_form', $form_state);
if (!$output) {
$output = array();
$output[] = ctools_ajax_command_replace('#modal-message', '<div id="modal-message">' . $form_state['message'] . '</div>');
$output[] = ctools_modal_command_dismiss();
}
ctools_ajax_render($output);
}
function module_test_form(&$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
function module_test_form_submit(&$form, &$form_state) {
$form_state['message'] = t('Message: %message', array('%message' => $form_state['values']['text']));
}
?>
Comments
CTools session at Drupalcon
Thanks Earl,
I was just about to dive in the CTools code after the session and the Panels BOF later on when you tweeted this post.
Great stuff.
TUc
Exportables
Great presentation but a pity you didn't manage to show example exportable usage.
hi there How do you
hi there
How do you implement that code
Hi Merlin, Thanks for your
Hi Merlin,
Thanks for your great work, True Ajax helper (so as panels and forms wizards, and...) was really missing in D6 !!
I was wondering how forms generated by ctools_modal_form_wrapper and rendered by ctools_ajax_render($output) could by themed ?
How can I mix html and ctools forms as output of the callback to build more complicated page structure without mix logic and template ?
keep movin' and Happy New Year !!!
They are normal forms. They
They are normal forms. They can be themed by creating a theme_FORM_ID function (and registering it in your hook_theme so it can be found).
Thanks for responding me
Thanks for responding me !
That's true but, as far as i know, i can't pass $form_values as an argument of my theming function, so how could i build a complex rendering in function of some values...
( In fact I would like to pass some argument in my form's building function but this isn't possible with ctools_modal_form_wrapper(), I could pass these arguments in the $form_values but what for if my theming function isn't aware of them ...)
Have you any clues ?
-forgive my bad english-
Ctools Form Wizard for Adding Nodes
Hi Merlin,
Thanks for all your incredible work.
Can the Ctools Form Wizard be used to create custom content types (nodes)?
Multistep form
I like the concept of your multistep form - caching an object. It meets one of the shortcomings of Drupal 6.
Is there some means of customising the buttons - i.e. changing the default names?
John, You can change the
John,
You can change the names of the buttons in the $form_info array. See the advanced help section of the chaos tools module.
$form_info = array('next text' => t('Save and Continue'),
);
I would like to know if there is any way to define a callback for the back button. This button seems to be the only one that doesn't have a callback. I have a form with several steps, if you fill out the current fields, then choose to go back, you will loose what you filled in. I would like to define a callback for the back button so that i can save the information regardless of whether the user is going forward or backwards thru the form. If anybody can help me out, that would be great.
That should be a feature
That should be a feature request in the ctools issue queue (ther emay actually already be one, so you should search and see)
CTools also provides a
CTools also provides a preprocess_page function that runs after this module and overrides the functionality for theme development settings. I have created a patch that sends the FALSE value for preprocess back to drupal so that when ctools or any other module tries to rewrite the stylesheets they will respect the work this module has done. The problem though is ctools will overwrite the import statements, so I don't have a solution for sites with > 31 stylesheets, which is probably the sole reason for this module's existence. Is there anyway to force this function to run AFTER CTools ?
Add new comment