7.x form.inc form_state_values_clean(&$form_state)

Removes internal Form API elements and buttons from submitted form values.

This function can be used when a module wants to store all submitted form values, for example, by serializing them into a single database column. In such cases, all internal Form API values and all form button elements should not be contained, and this function allows to remove them before the module proceeds to storage. Next to button elements, the following internal values are removed:

  • form_id
  • form_token
  • form_build_id
  • op

Parameters

$form_state: A keyed array containing the current state of the form, including submitted form values; altered by reference.

Related topics

8 calls to form_state_values_clean()
filter_admin_format_form_submit in modules/filter/filter.admin.inc
Form submission handler for filter_admin_format_form().
form_test_form_state_values_clean_advanced_form_submit in modules/simpletest/tests/form_test.module
Form submission handler for form_test_form_state_values_clean_advanced_form().
form_test_form_state_values_clean_form_submit in modules/simpletest/tests/form_test.module
Form submit handler for form_state_values_clean() test form.
path_admin_form_submit in modules/path/path.admin.inc
Form submission handler for path_admin_form().
system_settings_form_submit in modules/system/system.module
Form submission handler for system_settings_form().

... See full list

File

includes/form.inc, line 2249
Functions for form and batch generation and processing.

Code

function form_state_values_clean(&$form_state) {

  // Remove internal Form API values.
  unset($form_state['values']['form_id'], $form_state['values']['form_token'], $form_state['values']['form_build_id'], $form_state['values']['op']);

  // Remove button values.
  // form_builder() collects all button elements in a form. We remove the button
  // value separately for each button element.
  foreach ($form_state['buttons'] as $button) {

    // Remove this button's value from the submitted form values by finding
    // the value corresponding to this button.
    // We iterate over the #parents of this button and move a reference to
    // each parent in $form_state['values']. For example, if #parents is:
    //   array('foo', 'bar', 'baz')
    // then the corresponding $form_state['values'] part will look like this:
    // array(
    //   'foo' => array(
    //     'bar' => array(
    //       'baz' => 'button_value',
    //     ),
    //   ),
    // )
    // We start by (re)moving 'baz' to $last_parent, so we are able unset it
    // at the end of the iteration. Initially, $values will contain a
    // reference to $form_state['values'], but in the iteration we move the
    // reference to $form_state['values']['foo'], and finally to
    // $form_state['values']['foo']['bar'], which is the level where we can
    // unset 'baz' (that is stored in $last_parent).
    $parents = $button['#parents'];
    $last_parent = array_pop($parents);
    $key_exists = NULL;
    $values =& drupal_array_get_nested_value($form_state['values'], $parents, $key_exists);
    if ($key_exists && is_array($values)) {
      unset($values[$last_parent]);
    }
  }
}

Comments

ivanjaros’s picture

Shouldn't there be also a check for 'section__active_tab' ?

tbw17’s picture

I've run out of ideas where to look for this solution. I've searched endlessly all ajax errors I can find, none are specific to this form that I've located and none are specific to the modules involved.

It first started using Location with GMap. I contacted the maintainer and posted there about how the ajax autocomplete would never complete, so the form would always be submitted prior to ajax finishing and return a fatal error. After weeks of searching and reporting back for help, no luck. After uninstalling those modules, I installed Leaflet 7.x-1.0 beta2, its library (Leaflet v0.5.1-0), GeoCoder 7.x-1.2, Geofield 7.x-1.1, Geophp 7.x-1.7 and now when I add the geofield field to the content type via manage fields and click on format settings for Leaflet and save it (with or without making any changes to the settings) I receive the error message below and cannot proceed.

I sincerely apologize if this is NOT where to place this, but I can't tell where it should go...a new issue somewhere? If so, please advise and I'll post there. Too new to Drupal to know all the ins and outs, and appreciate any help in resolving this persistent "ajax error" issue. Thank you.

I am NOT using drupalforfirebug or jquery_update - the two modules everyone is saying need to be disabled...

I am using Drupal 7.7

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /system/ajax
StatusText: OK
ResponseText:
Fatal error: Call to undefined function element_validate_integer_positive() in /home/(my domain)/includes/form.inc on line 1356

tbw17’s picture

Sorry, that's Drupal 7.4 I'm using...couldn't edit the first note. Still don't think this is where it belongs...