Mercurial > defr > drupal > core
diff includes/form.inc @ 7:fff6d4c8c043 6.3
Drupal 6.3
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:30:28 +0100 |
parents | c1f4ac30525a |
children | acef7ccb09b5 |
line wrap: on
line diff
--- a/includes/form.inc Tue Dec 23 14:30:08 2008 +0100 +++ b/includes/form.inc Tue Dec 23 14:30:28 2008 +0100 @@ -1,5 +1,5 @@ <?php -// $Id: form.inc,v 1.265.2.4 2008/02/11 14:45:57 goba Exp $ +// $Id: form.inc,v 1.265.2.7 2008/06/25 09:58:09 dries Exp $ /** * @defgroup forms Form builder functions @@ -232,11 +232,12 @@ * Store a form in the cache */ function form_set_cache($form_build_id, $form, $form_state) { - $expire = max(ini_get('session.cookie_lifetime'), 86400); + // 6 hours cache life time for forms should be plenty. + $expire = 21600; - cache_set('form_'. $form_build_id, $form, 'cache_form', $expire); + cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire); if (!empty($form_state['storage'])) { - cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', $expire); + cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire); } } @@ -1270,20 +1271,30 @@ } /** - * Use this function to make changes to form values in the form validate - * phase, so they will be available in the submit phase in $form_state. + * Change submitted form values during the form processing cycle. * - * Specifically, if $form['#parents'] is array('foo', 'bar') - * and $value is 'baz' then this function will make - * $form_state['values']['foo']['bar'] to be 'baz'. + * Use this function to change the submitted value of a form item in the + * validation phase so that it persists in $form_state through to the + * submission handlers in the submission phase. * - * @param $form - * The form item. Keys used: #parents, #value + * Since $form_state['values'] can either be a flat array of values, or a tree + * of nested values, some care must be taken when using this function. + * Specifically, $form_item['#parents'] is an array that describes the branch of + * the tree whose value should be updated. For example, if we wanted to update + * $form_state['values']['one']['two'] to 'new value', we'd pass in + * $form_item['#parents'] = array('one', 'two') and $value = 'new value'. + * + * @param $form_item + * The form item that should have its value updated. Keys used: #parents, + * #value. In most cases you can just pass in the right element from the $form + * array. * @param $value - * The value for the form item. + * The new value for the form item. + * @param $form_state + * The array where the value change should be recorded. */ -function form_set_value($form, $value, &$form_state) { - _form_set_value($form_state['values'], $form, $form['#parents'], $value); +function form_set_value($form_item, $value, &$form_state) { + _form_set_value($form_state['values'], $form_item, $form_item['#parents'], $value); } /** @@ -1293,7 +1304,7 @@ * in $form_state['values'] if needed. Then we insert the value into * the right array. */ -function _form_set_value(&$form_values, $form, $parents, $value) { +function _form_set_value(&$form_values, $form_item, $parents, $value) { $parent = array_shift($parents); if (empty($parents)) { $form_values[$parent] = $value; @@ -1302,7 +1313,7 @@ if (!isset($form_values[$parent])) { $form_values[$parent] = array(); } - _form_set_value($form_values[$parent], $form, $parents, $value); + _form_set_value($form_values[$parent], $form_item, $parents, $value); } } @@ -1489,7 +1500,7 @@ } } - return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . $element['#value'] ."</fieldset>\n"; + return '<fieldset'. drupal_attributes($element['#attributes']) .'>'. ($element['#title'] ? '<legend>'. $element['#title'] .'</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">'. $element['#description'] .'</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') ."</fieldset>\n"; } /**