I am passing values from a form to a processing page. There are more fields but the one in concern is:
<label><input type="checkbox" name="plans[]" value="1" /> Number 1</label>
<label><input type="checkbox" name="plans[]" value="2" /> Number 2</label>
<label><input type="checkbox" name="plans[]" value="3" /> Number 3</label>
<label><input type="checkbox" name="plans[]" value="4" /> Number 4</label>
I know the values are submitting corretly and exist when printing $_POST on the processing page displays the plans array inside my $_POST array.
On my processing page (submitted from form), if an error occurs within the data, the original $_POST values are stored as a new $_SESSION[‘fields’] variable so that they may repopulate the fields when the page redirects to the previous page.
$_SESSION['fields'] = $_POST;
If an error does occur, my actual form page pulls the original field values from the SESSION variable with the following code:
if(isset($_SESSION['fields'])) {
$fields = array();
$fields = $_SESSION['fields'];
unset($_SESSION['fields']);
}
When printing the $fields variable, all original post values appear EXCEPT the original arrays (checkboxes). They do not show up at all (name, address, etc do however).
Are you unable to pass an array within an array by reference in this manner?
edit
The flow is this:
- form.php
- (all values are sent POST to processing page) processing.php
- POST values are validated and if any errors or issues exist, $_SESSION[‘fields’] = $_POST
- redirect back to form.php to fix error, highlight issue, and display all original values into fields.
Make sure that you are not doing any type of data manipulation before you pass it to the SESSION variable such as an array_pop() or in your case the array_map(). The reason why your array_map (strtoupper) is breaking your array, is the strtoupper is trying to be performed on the Array and not the individual elements. To fix this you could check for is_array in your mapping and then loop in there as well or setup a recursive function incase of nested array elements.