Mercurial > defr > drupal > core
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:2cfdc3c92142 | 7:fff6d4c8c043 |
---|---|
1 <?php | 1 <?php |
2 // $Id: form.inc,v 1.265.2.4 2008/02/11 14:45:57 goba Exp $ | 2 // $Id: form.inc,v 1.265.2.7 2008/06/25 09:58:09 dries Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @defgroup forms Form builder functions | 5 * @defgroup forms Form builder functions |
6 * @{ | 6 * @{ |
7 * Functions that build an abstract representation of a HTML form. | 7 * Functions that build an abstract representation of a HTML form. |
230 | 230 |
231 /** | 231 /** |
232 * Store a form in the cache | 232 * Store a form in the cache |
233 */ | 233 */ |
234 function form_set_cache($form_build_id, $form, $form_state) { | 234 function form_set_cache($form_build_id, $form, $form_state) { |
235 $expire = max(ini_get('session.cookie_lifetime'), 86400); | 235 // 6 hours cache life time for forms should be plenty. |
236 | 236 $expire = 21600; |
237 cache_set('form_'. $form_build_id, $form, 'cache_form', $expire); | 237 |
238 cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire); | |
238 if (!empty($form_state['storage'])) { | 239 if (!empty($form_state['storage'])) { |
239 cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', $expire); | 240 cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire); |
240 } | 241 } |
241 } | 242 } |
242 | 243 |
243 /** | 244 /** |
244 * Retrieves a form using a form_id, populates it with $form_state['values'], | 245 * Retrieves a form using a form_id, populates it with $form_state['values'], |
1268 return (string)$edit; | 1269 return (string)$edit; |
1269 } | 1270 } |
1270 } | 1271 } |
1271 | 1272 |
1272 /** | 1273 /** |
1273 * Use this function to make changes to form values in the form validate | 1274 * Change submitted form values during the form processing cycle. |
1274 * phase, so they will be available in the submit phase in $form_state. | 1275 * |
1275 * | 1276 * Use this function to change the submitted value of a form item in the |
1276 * Specifically, if $form['#parents'] is array('foo', 'bar') | 1277 * validation phase so that it persists in $form_state through to the |
1277 * and $value is 'baz' then this function will make | 1278 * submission handlers in the submission phase. |
1278 * $form_state['values']['foo']['bar'] to be 'baz'. | 1279 * |
1279 * | 1280 * Since $form_state['values'] can either be a flat array of values, or a tree |
1280 * @param $form | 1281 * of nested values, some care must be taken when using this function. |
1281 * The form item. Keys used: #parents, #value | 1282 * Specifically, $form_item['#parents'] is an array that describes the branch of |
1283 * the tree whose value should be updated. For example, if we wanted to update | |
1284 * $form_state['values']['one']['two'] to 'new value', we'd pass in | |
1285 * $form_item['#parents'] = array('one', 'two') and $value = 'new value'. | |
1286 * | |
1287 * @param $form_item | |
1288 * The form item that should have its value updated. Keys used: #parents, | |
1289 * #value. In most cases you can just pass in the right element from the $form | |
1290 * array. | |
1282 * @param $value | 1291 * @param $value |
1283 * The value for the form item. | 1292 * The new value for the form item. |
1284 */ | 1293 * @param $form_state |
1285 function form_set_value($form, $value, &$form_state) { | 1294 * The array where the value change should be recorded. |
1286 _form_set_value($form_state['values'], $form, $form['#parents'], $value); | 1295 */ |
1296 function form_set_value($form_item, $value, &$form_state) { | |
1297 _form_set_value($form_state['values'], $form_item, $form_item['#parents'], $value); | |
1287 } | 1298 } |
1288 | 1299 |
1289 /** | 1300 /** |
1290 * Helper function for form_set_value(). | 1301 * Helper function for form_set_value(). |
1291 * | 1302 * |
1292 * We iterate over $parents and create nested arrays for them | 1303 * We iterate over $parents and create nested arrays for them |
1293 * in $form_state['values'] if needed. Then we insert the value into | 1304 * in $form_state['values'] if needed. Then we insert the value into |
1294 * the right array. | 1305 * the right array. |
1295 */ | 1306 */ |
1296 function _form_set_value(&$form_values, $form, $parents, $value) { | 1307 function _form_set_value(&$form_values, $form_item, $parents, $value) { |
1297 $parent = array_shift($parents); | 1308 $parent = array_shift($parents); |
1298 if (empty($parents)) { | 1309 if (empty($parents)) { |
1299 $form_values[$parent] = $value; | 1310 $form_values[$parent] = $value; |
1300 } | 1311 } |
1301 else { | 1312 else { |
1302 if (!isset($form_values[$parent])) { | 1313 if (!isset($form_values[$parent])) { |
1303 $form_values[$parent] = array(); | 1314 $form_values[$parent] = array(); |
1304 } | 1315 } |
1305 _form_set_value($form_values[$parent], $form, $parents, $value); | 1316 _form_set_value($form_values[$parent], $form_item, $parents, $value); |
1306 } | 1317 } |
1307 } | 1318 } |
1308 | 1319 |
1309 /** | 1320 /** |
1310 * Retrieve the default properties for the defined element type. | 1321 * Retrieve the default properties for the defined element type. |
1487 if ($element['#collapsed']) { | 1498 if ($element['#collapsed']) { |
1488 $element['#attributes']['class'] .= ' collapsed'; | 1499 $element['#attributes']['class'] .= ' collapsed'; |
1489 } | 1500 } |
1490 } | 1501 } |
1491 | 1502 |
1492 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"; | 1503 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"; |
1493 } | 1504 } |
1494 | 1505 |
1495 /** | 1506 /** |
1496 * Format a radio button. | 1507 * Format a radio button. |
1497 * | 1508 * |