rmpotter Posted September 9, 2009 Share Posted September 9, 2009 Basically I have a very complex form and am looking to save all the data for viewing later. Is there an easy way to save the entire form and reload all the content from it on the same form later? Link to comment Share on other sites More sharing options...
chibineku Posted September 9, 2009 Share Posted September 9, 2009 You could quickly WHILE through the form inputs, sanitizing them and adding them to an associative array, then implode the array into a string to store in a database, so you've only made one db call, and then when you want the values again, read the one field with all the data and explode it into an array. You could have the value attribute of the input fields set to something like <?php echo ($_SESSION["fieldname"]?$_SESSION["fieldname"]:""); ?> and when you're reading the values again, set them to the session variable. But only good for temporary storage, as it compiles all your data into one field. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 9, 2009 Share Posted September 9, 2009 It's probably better to use serialize and unserialize instead of implode and explode, serialize is specifically for creating a string representation of a structure like an array. You could serialize all of $_POST, for example, and store that in the session. Link to comment Share on other sites More sharing options...
rmpotter Posted September 9, 2009 Author Share Posted September 9, 2009 It's probably better to use serialize and unserialize instead of implode and explode, serialize is specifically for creating a string representation of a structure like an array. You could serialize all of $_POST, for example, and store that in the session.This is what I have done in the past and it works awseome for simple forms. This form is very complex and reloading all the values would be time consuming to program and prone to error... Is it possible to take a PHP array and load it into a java array? I would hope that by doing so I could run through each variable by name and repopulate it once the form has loaded again. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 9, 2009 Share Posted September 9, 2009 You can use the json_encode function to convert a PHP array into a Javascript structure. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.