| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: multipage_form_example.module,v 1.8 2006/04/08 03:35:39 drumm Exp $ |
// $Id: multipage_form_example.module,v 1.10 2008/10/12 08:52:36 davereid Exp $ |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 17 |
/** |
/** |
| 18 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 19 |
*/ |
*/ |
| 20 |
function multipage_form_example_menu() { |
function multipage_form_example_menu($may_cache) { |
| 21 |
$items['node/add/multipage_form_example'] = array( |
$items = array(); |
| 22 |
'title' => t('multipage form example'), |
|
| 23 |
'access' => TRUE, |
if (!$may_cache) { |
| 24 |
); |
|
| 25 |
|
$items[] = array('title' => t('multipage form example'), |
| 26 |
|
'path' => 'node/add/multipage_form_example', |
| 27 |
|
'access' => TRUE, |
| 28 |
|
); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
return $items; |
return $items; |
| 32 |
} |
} |
| 42 |
* Implementation of hook_node_info(). |
* Implementation of hook_node_info(). |
| 43 |
*/ |
*/ |
| 44 |
function multipage_form_example_node_info() { |
function multipage_form_example_node_info() { |
| 45 |
return array( |
return array('multipage_form_example' => array('name' => t('multipage form example'), 'base' => 'multipage_form_example')); |
|
'multipage_form_example' => array( |
|
|
'name' => t('multipage form example'), |
|
|
'base' => 'multipage_form_example' |
|
|
) |
|
|
); |
|
| 46 |
} |
} |
| 47 |
|
|
| 48 |
/** |
/** |
| 68 |
'#values' => array('n' => 'north', 'e' => 'east', 'w' => 'west', 's' => 'south', ), |
'#values' => array('n' => 'north', 'e' => 'east', 'w' => 'west', 's' => 'south', ), |
| 69 |
); |
); |
| 70 |
|
|
|
|
|
|
|
|
| 71 |
// Helper for our multipage - does field switching, sets options |
// Helper for our multipage - does field switching, sets options |
| 72 |
// based on validated $form_values instead of $_POST, and so forth. |
// based on validated $form_values instead of $_POST, and so forth. |
| 73 |
$form['#pre_render'] = array('multipage_form_example_pre_render'); |
$form['#pre_render'] = array('multipage_form_example_pre_render'); |
| 159 |
$content = ''; |
$content = ''; |
| 160 |
|
|
| 161 |
if (in_array($form['page']['#value'], array(3,4))) { |
if (in_array($form['page']['#value'], array(3,4))) { |
| 162 |
$content .= '<p>'. t('Your favorite person is %person, and they %like gummi bears.', array('%person' => check_plain($form['person']['fav_person']['#value']), '%like' => ($form['person']['fav_gummi']['#value'] ? t('like') : t('don\'t like')))) .'</p>'; |
$content .= '<p>' . t('Your favorite person is %person, and they %like gummi bears.', array('%person' => check_plain($form['person']['fav_person']['#value']), '%like' => ($form['person']['fav_gummi']['#value'] ? t('like') : t('don\'t like')))) . '</p>'; |
| 163 |
} |
} |
| 164 |
|
|
| 165 |
if (in_array($form['page']['#value'], array(4))) { |
if (in_array($form['page']['#value'], array(4))) { |
| 166 |
$content .= '<p>'. t('Your favorite color is %color, and your favorite number is %number.', array('%color' => check_plain($form['fav_color']['#value']), '%number' => check_plain($form['fav_number']['#value']))); |
$content .= '<p>' . t('Your favorite color is %color, and your favorite number is %number.', array('%color' => check_plain($form['fav_color']['#value']), '%number' => check_plain($form['fav_number']['#value']))); |
| 167 |
} |
} |
| 168 |
|
|
| 169 |
foreach (element_children($form) as $key) { |
foreach (element_children($form) as $key) { |
| 297 |
$nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = 'node_nid'")); |
$nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = 'node_nid'")); |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
variable_set('multipage_form_example_'. $nid, $array); |
variable_set('multipage_form_example_' . $nid, $array); |
| 301 |
} |
} |
| 302 |
|
|
| 303 |
/** |
/** |
| 308 |
* every time a node is loaded, and allows us to do some loading of our own. |
* every time a node is loaded, and allows us to do some loading of our own. |
| 309 |
*/ |
*/ |
| 310 |
function multipage_form_example_load($node) { |
function multipage_form_example_load($node) { |
| 311 |
$additions = variable_get('multipage_form_example_'. $node->nid, NULL); |
$additions = variable_get('multipage_form_example_' . $node->nid, NULL); |
| 312 |
$additions = (object) $additions; |
$additions = (object) $additions; |
| 313 |
return $additions; |
return $additions; |
| 314 |
} |
} |
| 320 |
*/ |
*/ |
| 321 |
function multipage_form_example_delete($node) { |
function multipage_form_example_delete($node) { |
| 322 |
// Notice that we're matching all revision, by using the node's nid. |
// Notice that we're matching all revision, by using the node's nid. |
| 323 |
variable_del('multipage_form_example_'. $node->nid); |
variable_del('multipage_form_example_' . $node->nid); |
| 324 |
} |
} |
| 325 |
|
|
| 326 |
/** |
/** |
| 430 |
* The new value for the attribute. |
* The new value for the attribute. |
| 431 |
*/ |
*/ |
| 432 |
function multipage_form_set_attribute(&$element, $key, $new_value) { |
function multipage_form_set_attribute(&$element, $key, $new_value) { |
| 433 |
$element['#multipage_form_original_'. $key] = $element[$key]; |
$element['#multipage_form_original_' . $key] = $element[$key]; |
| 434 |
$element[$key] = $new_value; |
$element[$key] = $new_value; |
| 435 |
} |
} |
| 436 |
|
|
| 453 |
* element |
* element |
| 454 |
*/ |
*/ |
| 455 |
function multipage_form_example_elements() { |
function multipage_form_example_elements() { |
| 456 |
$type['hidden_array'] = array('#input' => TRUE, '#process' => array('expand_hidden_array' => array()), '#tree' => TRUE); |
$type['hidden_array'] = array('#input' => TRUE, '#process' => array('expand_hidden_array' => array()), '#tree' => TRUE); |
| 457 |
return $type; |
return $type; |
| 458 |
} |
} |
| 459 |
|
|
| 460 |
function expand_hidden_array($element) { |
function expand_hidden_array($element) { |