function _prepopulate_request_walk in Prepopulate 7.2
Same name and namespace in other branches
- 6.2 prepopulate.module \_prepopulate_request_walk()
Internal helper to set element values from the $_REQUEST variable.
Parameters
array &$form: A form element.
mixed &$request_slice: String or array. Value(s) to be applied to the element.
1 call to _prepopulate_request_walk()
- prepopulate_after_build in ./
prepopulate.module - An #after_build function to set the values prepopulated in the request.
File
- ./
prepopulate.module, line 55 - Fill form elements with data from GET or POST values.
Code
function _prepopulate_request_walk(&$form, &$request_slice) {
$limited_types = array(
'actions',
'button',
'token',
'value',
'hidden',
'image_button',
'password',
'password_confirm',
'markup',
);
if (is_array($request_slice)) {
foreach (array_keys($request_slice) as $request_variable) {
$and_checks = array(
'is child' => element_child($request_variable),
'in form' => !empty($form[$request_variable]),
);
if (array_sum($and_checks) == count($and_checks)) {
$or_checks = array(
'no #type set' => !isset($form[$request_variable]['#type']),
'language container' => isset($form[$request_variable]['#language']) && isset($form[$request_variable][$form[$request_variable]['#language']]['#type']) && !in_array($form[$request_variable][$form[$request_variable]['#language']]['#type'], $limited_types),
'container' => isset($form[$request_variable]['#type']) && $form[$request_variable]['#type'] == 'container' && isset($form[$request_variable]['#language']) && isset($form[$request_variable][$form[$request_variable]['#language']][0]['#type']) && $form[$request_variable][$form[$request_variable]['#language']][0]['#type'] == 'text_format',
'allowed #type' => isset($form[$request_variable]['#type']) && !in_array($form[$request_variable]['#type'], $limited_types),
);
if (array_sum($or_checks) > 0) {
if (!isset($form[$request_variable]['#access']) || $form[$request_variable]['#access'] != FALSE) {
_prepopulate_request_walk($form[$request_variable], $request_slice[$request_variable]);
}
}
}
}
if (!empty($form['#default_value']) && is_array($form['#default_value'])) {
$form['#default_value'] = array_merge($form['#default_value'], $request_slice);
}
}
else {
if ($form['#type'] == 'markup' || empty($form['#type'])) {
$form['#value'] = check_plain($request_slice);
}
else {
$form['#value'] = $request_slice;
}
if ($form['#type'] == 'checkboxes' || $form['#type'] == 'checkbox') {
if (!empty($form['#value'])) {
$form['#checked'] = TRUE;
}
else {
$form['#checked'] = FALSE;
}
}
}
}