function mefibs_set_element_name_recursive in MEFIBS - More exposed forms in blocks 7
Recursivly prefix the #name attribute of all elements in a form.
Parameters
array $form: Form API array.
string $prefix: The string to use as a prefix.
1 call to mefibs_set_element_name_recursive()
- mefibs_exposed_block_form in ./
mefibs.module - Form builder for the additional exposed form.
File
- ./
mefibs.module, line 811 - Primarily Drupal hooks and global API functions to manipulate views and to provide an additional block with an exposed filter form.
Code
function mefibs_set_element_name_recursive(&$form, $prefix) {
$valid_element_types = array(
'textfield',
'textarea',
'select',
'checkbox',
'checkboxes',
'radio',
'radios',
'hidden',
);
foreach (element_children($form) as $element) {
if ($element == 'mefibs_form') {
continue;
}
if (isset($form[$element]['#type']) && in_array($form[$element]['#type'], $valid_element_types)) {
$form[$element]['#name'] = $prefix . '-' . $form[$element]['#name'];
if (!empty($form[$element]['#multiple'])) {
$form[$element]['#attributes']['name'] = $form[$element]['#name'] . '[]';
}
}
if (count(element_children($form[$element]))) {
mefibs_set_element_name_recursive($form[$element], $prefix);
}
}
}