I’m trying to get the $_POST value from a previous page.
<form method="POST">
<input type="checkbox" name="hey"<?php if (isset($_POST['hey'])) echo " checked"; ?>>
<input type="submit">
</form>
And any values must be kept in the hidden form, and it makes that the form values doesn’t update if you change a check:
<form method="POST">
<?php
if ($_POST['hey'] == 'on') {
?>
<input type="hidden" name="hey" value="on" />
<?php
}
?>
<input type="checkbox" name="hey"<?php if (isset($_POST['hey'])) echo " checked"; ?>>
<input type="submit">
</form>
This structure may sound weird (due to the CMS specification), anyway, if it changes I have to get input values, not hidden values, and all hidden forms should be written in the source. Any idea?
You use plural – so I assume it would be two or more variables. Set one hidden field in second page form call it previous_variables, put there all previous variables with their names, serialized, or as JSON string, when form submitted, unserialize or decode JSON, as start point and override if new values on second form happens to be more actual…