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.