function rules_forms_build_elements in Rules Forms Support 7
Builds elements of a form for storage in a variable.
Parameters
mixed $form: The form whose elements info is being saved.
mixed $form_info: Current form information for this form to be populated with elements.
string $parent: A string identifying the parent of the current element being processed. This parameter should not be passed in and is used only recursively.
See also
1 call to rules_forms_build_elements()
- rules_forms_after_build in ./
rules_forms.module - Add element IDs on the form if the setting is enabled.
File
- ./
rules_forms.module, line 301 - Rules Forms Support provides events, conditions, and actions for site forms.
Code
function rules_forms_build_elements($form, &$form_info, $parent = '') {
foreach (element_children($form) as $key) {
// Only save element that have title or value and are not hidden or tokens.
if (isset($form[$key]['#type'])) {
if (isset($form[$key]['#title']) && !in_array($form[$key]['#type'], array(
'hidden',
'token',
)) || $form[$key]['#type'] == 'submit' || $form[$key]['#type'] == 'button') {
$element_id = $form[$key]['#type'] . ':' . $parent . $key;
$element_key = isset($form[$key]['#title']) ? ucfirst($form[$key]['#title']) : $key;
$form_info['elements'][$element_id] = array(
'type' => $form[$key]['#type'],
'label' => $form[$key]['#type'] == 'submit' || $form[$key]['#type'] == 'button' ? $form[$key]['#value'] : $element_key,
);
// If this is a submit element, add it for use in adding button level
// validation and submission handlers.
if ($form_info['buttons'] && ($form[$key]['#type'] == 'submit' || $form[$key]['#type'] == 'button')) {
if (isset($form[$key]['#submit'])) {
$form_info['submit'][$element_id] = isset($form[$key]['#value']) ? $form[$key]['#value'] : $key;
}
}
if (isset($form[$key]['#options'])) {
$form_info['elements'][$element_id]['options'] = $form[$key]['#options'];
}
}
}
// Recursive call on children.
rules_forms_build_elements($form[$key], $form_info, $parent . $key . ':');
}
}