Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.265.2.10 diff -u -r1.265.2.10 form.inc --- includes/form.inc 13 Aug 2008 23:59:12 -0000 1.265.2.10 +++ includes/form.inc 12 Sep 2008 13:27:59 -0000 @@ -294,6 +294,7 @@ $args = func_get_args(); $form = call_user_func_array('drupal_retrieve_form', $args); $form['#post'] = $form_state['values']; + _form_set_current($form); drupal_prepare_form($form_id, $form, $form_state); drupal_process_form($form_id, $form, $form_state); } @@ -561,12 +562,6 @@ * not be repeated in the submission step. */ function drupal_validate_form($form_id, $form, &$form_state) { - static $validated_forms = array(); - - if (isset($validated_forms[$form_id])) { - return; - } - // If the session token was set by drupal_prepare_form(), ensure that it // matches the current user's session. if (isset($form['#token'])) { @@ -575,9 +570,7 @@ form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.')); } } - _form_validate($form, $form_state, $form_id); - $validated_forms[$form_id] = TRUE; } /** @@ -788,13 +781,14 @@ */ function form_set_error($name = NULL, $message = '') { static $form = array(); - if (isset($name) && !isset($form[$name])) { - $form[$name] = $message; + $build_id = _form_set_current(); + if (isset($name) && !isset($form[$build_id][$name])) { + $form[$build_id][$name] = $message; if ($message) { drupal_set_message($message, 'error'); } } - return $form; + return $form[$build_id]; } /** @@ -1325,6 +1319,27 @@ } /** + * Stores the current form id, generating it if missing + * + * @param $form + * The curren form + * @return + * The current id + */ + +function _form_set_current(&$form = NULL) { + static $current = 'current'; + if (isset($form)) { + // FIXME: is #current_build_id really needed or we can use #build_id instead? + $current = isset($form['#build_id']) ? $form['#build_id'] : $form['#current_build_id']; + if (empty($current)) { + $current = $form['#current_build_id'] = 'form-'. md5(uniqid(mt_rand(), TRUE)); + } + } + return $current; +} + +/** * Retrieve the default properties for the defined element type. */ function _element_info($type, $refresh = NULL) {