function field_add_more_submit
Submit handler for the "Add another item" button of a field form.
This handler is run regardless of whether JS is enabled or not. It makes changes to the form state. If the button was clicked with JS disabled, then the page is reloaded with the complete rebuilt form. If the button was clicked with JS enabled, then ajax_form_callback() calls field_add_more_js() to return just the changed part of the form.
1 string reference to 'field_add_more_submit'
- field_multiple_value_form in modules/
field/ field.form.inc - Special handling to create form elements for multiple values.
File
-
modules/
field/ field.form.inc, line 443
Code
function field_add_more_submit($form, &$form_state) {
$button = $form_state['triggering_element'];
// Go one level up in the form, to the widgets container.
$element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -1));
$field_name = $element['#field_name'];
$langcode = $element['#language'];
$parents = $element['#field_parents'];
// Increment the items count.
$field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);
$field_state['items_count']++;
field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);
$form_state['rebuild'] = TRUE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.