Closed (fixed)
Project:
Dialog
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
24 Dec 2009 at 01:28 UTC
Updated:
31 Jan 2011 at 21:44 UTC
This function is analogous to drupal_get_form() and provides a simple way to place a form in a dialog, without having to write a callback.
Example:
In a normal, non-dialog menu definition, you might do the following:
$item['foo/bar'] = array(
'title' => 'Foo bar',
'page callback' => 'drupal_get_form',
'page arguments' => array('foo_bar_form'),
...
);
And now with this function you can create a similar menu item like this:
$item['foo/bar/%ctools_js'] = array(
'title' => 'Foo bar',
'page callback' => 'dialog_get_form',
'page arguments' => array('foo_bar_form', 2),
...
);
dialog_get_form will handle all the js/non-js form building, passing on any additional arguments to the form builder. Upon form submission, the ajax response is created in one of the following ways:
Here is what the user login example looks like now.
function dialog_user_menu() {
$items['user/login/%ctools_js'] = array(
'title' => 'Log in',
'page callback' => 'dialog_get_form',
'page arguments' => array('user_login', 2),
'access callback' => 'user_is_anonymous',
'type' => MENU_CALLBACK,
'file' => 'user.pages.inc',
'file path' => drupal_get_path('module', 'user'),
);
return $items;
}
Thats it, just a menu declaration, no callback needed! Notice though, that you must take care to include the file where the form builder is located.
| Comment | File | Size | Author |
|---|---|---|---|
| dialog_get_form.patch | 2.21 KB | zroger |
Comments
Comment #1
zroger commentedcommitted to 6.x
Comment #3
miraclestyle commentedForgive me if I am wrong, as I am not experienced developer, but shouldn't the last function call in "dialog_get_form":
include the "$args" as well:
???
Once again, my apologies if this is wrong!
Cheers.
Elvin.
Comment #4
entrigan commentedDoes using this function then restrict the dialog to only use the defaults? I ask this because normally I put the configuration in the menu callback function, e.g.
$output[$i]['options']['resizable'] = FALSE;EDIT: nm, this function can be called from within the callback function, so everything can be handled per normal.
Comment #5
drewish commentedctools_ajax_render() calls exit()