Mercurial > defr > drupal > core
comparison includes/form.inc @ 9:acef7ccb09b5 6.4
Drupal 6.4
| author | Franck Deroche <webmaster@defr.org> |
|---|---|
| date | Tue, 23 Dec 2008 14:32:08 +0100 |
| parents | fff6d4c8c043 |
| children | 589fb7c02327 |
comparison
equal
deleted
inserted
replaced
| 8:85cbd6048071 | 9:acef7ccb09b5 |
|---|---|
| 1 <?php | 1 <?php |
| 2 // $Id: form.inc,v 1.265.2.7 2008/06/25 09:58:09 dries Exp $ | 2 // $Id: form.inc,v 1.265.2.10 2008/08/13 23:59:12 drumm 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. |
| 98 $args_temp = $args; | 98 $args_temp = $args; |
| 99 $args_temp[0] = &$form_state; | 99 $args_temp[0] = &$form_state; |
| 100 array_unshift($args_temp, $form_id); | 100 array_unshift($args_temp, $form_id); |
| 101 | 101 |
| 102 $form = call_user_func_array('drupal_retrieve_form', $args_temp); | 102 $form = call_user_func_array('drupal_retrieve_form', $args_temp); |
| 103 $form_build_id = 'form-'. md5(mt_rand()); | 103 $form_build_id = 'form-'. md5(uniqid(mt_rand(), true)); |
| 104 $form['#build_id'] = $form_build_id; | 104 $form['#build_id'] = $form_build_id; |
| 105 drupal_prepare_form($form_id, $form, $form_state); | 105 drupal_prepare_form($form_id, $form, $form_state); |
| 106 // Store a copy of the unprocessed form for caching and indicate that it | 106 // Store a copy of the unprocessed form for caching and indicate that it |
| 107 // is cacheable if #cache will be set. | 107 // is cacheable if #cache will be set. |
| 108 $original_form = $form; | 108 $original_form = $form; |
| 214 drupal_process_form($form_id, $form, $form_state); | 214 drupal_process_form($form_id, $form, $form_state); |
| 215 return $form; | 215 return $form; |
| 216 } | 216 } |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * Fetch a form from cache. | 219 * Store a form in the cache. |
| 220 */ | |
| 221 function form_get_cache($form_build_id, &$form_state) { | |
| 222 if ($cached = cache_get('form_'. $form_build_id, 'cache_form')) { | |
| 223 $form = $cached->data; | |
| 224 if ($cached = cache_get('storage_'. $form_build_id, 'cache_form')) { | |
| 225 $form_state['storage'] = $cached->data; | |
| 226 } | |
| 227 return $form; | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 /** | |
| 232 * Store a form in the cache | |
| 233 */ | 220 */ |
| 234 function form_set_cache($form_build_id, $form, $form_state) { | 221 function form_set_cache($form_build_id, $form, $form_state) { |
| 222 global $user; | |
| 235 // 6 hours cache life time for forms should be plenty. | 223 // 6 hours cache life time for forms should be plenty. |
| 236 $expire = 21600; | 224 $expire = 21600; |
| 237 | 225 |
| 226 if ($user->uid) { | |
| 227 $form['#cache_token'] = drupal_get_token(); | |
| 228 } | |
| 238 cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire); | 229 cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire); |
| 239 if (!empty($form_state['storage'])) { | 230 if (!empty($form_state['storage'])) { |
| 240 cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire); | 231 cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire); |
| 232 } | |
| 233 } | |
| 234 | |
| 235 /** | |
| 236 * Fetch a form from cache. | |
| 237 */ | |
| 238 function form_get_cache($form_build_id, &$form_state) { | |
| 239 global $user; | |
| 240 if ($cached = cache_get('form_'. $form_build_id, 'cache_form')) { | |
| 241 $form = $cached->data; | |
| 242 if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) { | |
| 243 if ($cached = cache_get('storage_'. $form_build_id, 'cache_form')) { | |
| 244 $form_state['storage'] = $cached->data; | |
| 245 } | |
| 246 return $form; | |
| 247 } | |
| 241 } | 248 } |
| 242 } | 249 } |
| 243 | 250 |
| 244 /** | 251 /** |
| 245 * Retrieves a form using a form_id, populates it with $form_state['values'], | 252 * Retrieves a form using a form_id, populates it with $form_state['values'], |
| 1515 * @ingroup themeable | 1522 * @ingroup themeable |
| 1516 */ | 1523 */ |
| 1517 function theme_radio($element) { | 1524 function theme_radio($element) { |
| 1518 _form_set_class($element, array('form-radio')); | 1525 _form_set_class($element, array('form-radio')); |
| 1519 $output = '<input type="radio" '; | 1526 $output = '<input type="radio" '; |
| 1527 $output .= 'id="'. $element['#id'] .'" '; | |
| 1520 $output .= 'name="'. $element['#name'] .'" '; | 1528 $output .= 'name="'. $element['#name'] .'" '; |
| 1521 $output .= 'value="'. $element['#return_value'] .'" '; | 1529 $output .= 'value="'. $element['#return_value'] .'" '; |
| 1522 $output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' '; | 1530 $output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' '; |
| 1523 $output .= drupal_attributes($element['#attributes']) .' />'; | 1531 $output .= drupal_attributes($element['#attributes']) .' />'; |
| 1524 if (!is_null($element['#title'])) { | 1532 if (!is_null($element['#title'])) { |
| 1731 '#return_value' => check_plain($key), | 1739 '#return_value' => check_plain($key), |
| 1732 '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL, | 1740 '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL, |
| 1733 '#attributes' => $element['#attributes'], | 1741 '#attributes' => $element['#attributes'], |
| 1734 '#parents' => $element['#parents'], | 1742 '#parents' => $element['#parents'], |
| 1735 '#id' => form_clean_id('edit-'. implode('-', $parents_for_id)), | 1743 '#id' => form_clean_id('edit-'. implode('-', $parents_for_id)), |
| 1744 '#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL, | |
| 1736 ); | 1745 ); |
| 1737 } | 1746 } |
| 1738 } | 1747 } |
| 1739 } | 1748 } |
| 1740 return $element; | 1749 return $element; |
