Page 1 of 1

Retaining array values after submit

Posted: Wed Oct 14, 2009 11:56 pm
by denniss
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'])));

Re: Retaining array values after submit

Posted: Thu Oct 15, 2009 2:25 am
by requinix
It should be

Code: Select all

<?php echo htmlentities(serialize($arrVars)); ?>
and

Code: Select all

if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) $_POST["storeArr"] = stripslashes($_POST["storeArr"]);
$arrVars = unserialize($_POST['storeArr']);
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.)

Re: Retaining array values after submit

Posted: Thu Oct 15, 2009 12:14 pm
by denniss
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']