I am wondering whether there is a way to retain array values after submission. This is what I have tried so far and it is not working. The array contains objects that I created on my own.
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="set" id="set" value="Set Variables" />
<input name="storeArr" name="storeArr" type="hidden" value="<?php echo serialize(htmlentities($arrVars)); ?>" />
</form>
and after submission i do.
$arrVars = unserialize(html_entity_decode(stripslashes($_POST['storeArr'])));
Retaining array values after submit
Moderator: General Moderators
Re: Retaining array values after submit
It should be
and
If the array has actual objects then their definitions (ie, the "class Foo {...}" code) must be given or included in the new script. PHP does not store the full definition of a class - just the data - so if it doesn't know how to reconstruct the object it won't work as you want. (Using __autoload will work.)
Code: Select all
<?php echo htmlentities(serialize($arrVars)); ?>Code: Select all
if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) $_POST["storeArr"] = stripslashes($_POST["storeArr"]);
$arrVars = unserialize($_POST['storeArr']);Re: Retaining array values after submit
the definition is included in the new script by using require_once(); plus I am working only under 1 script here by using $_SERVER['PHP_SELF']