function _webform_submit_grid in Webform 5.2
Same name and namespace in other branches
- 5 components/grid.inc \_webform_submit_grid()
- 6.2 components/grid.inc \_webform_submit_grid()
Translates the submitted 'safe' form values back into their un-edited original form.
Parameters
$data: The POST data associated with the component
$component: An array of information describing the component, directly correlating to the webform_component database schema
Return value
Nothing
File
- components/
grid.inc, line 166 - Webform module grid component.
Code
function _webform_submit_grid(&$data, $component) {
$options = drupal_map_assoc(array_flip(_webform_grid_options($component['extra']['options'])));
// Questions are a bit more tricky, since quotes were removed from them in
// _webform_render_grid(). Build a list of no_quotes => with_qoutes questions.
$questions = array();
foreach (_webform_grid_options($component['extra']['questions']) as $key => $question) {
$safe_question = str_replace(array(
'"',
"'",
), '', $question);
$questions[$safe_question] = $question;
}
if (is_array($data)) {
foreach ($data as $key => $value) {
if ($value !== '') {
$data[$key] = $options[$value];
}
}
}
elseif ($data !== '') {
$data = $options[$data];
}
// Put the form in the original option order before saving.
// Return the final data with the quotes back in place.
$ordered_data = array();
foreach ($questions as $safe_question => $question) {
if (isset($data[$safe_question])) {
$ordered_data[$question] = $data[$safe_question];
}
}
$data = $ordered_data;
}