Hi, What i am trying to do but dont know how do is create a function which i want to call after i have posted a form. This function will store all POST values in a global array. I have a sequence of about 4 pages all with forms on. I want to call the function each time i post each page so all fields are stored in the array which i can call at the end. Any help would be much appreciated. Cheers, Adam
Create an array with all the POST fields you want to store in it and put that array in session. Every time you want to add / modify elements of POST data, take out the array from session, do add / modify and put back the array in session. Finally after sequence of all pages, you can do processing on all the POST data at once as per your wish
Thanks for that, i am now going to put the values in an array and then store the array in a session. Please can someone help though with putting the data in an array. I need each value of the array to be called the name of the post and it to contain the post value. I have tried a few things but can't get my head around it.
$_SESSION['form_name'] = array('name' => $_POST['name_field'], 'phone' => $_POST['phone']); PHP: (continue with whatever you need from the form like that)
foreach ($_POST as $key=>$value){ $form_values[$key] = $value; } $_SESSION['form_values'] = $form_values; PHP: something like this?
Using foreach() this way makes no sense at all. You're unnecessarily creating a copy of the $_POST array, which already holds the data of hundreds of fields. Do this on the first page: $_SESSION['fields'] = $_POST; PHP: ... and this on the other pages: $_SESSION['fields'] = array_merge($_SESSION['fields'], $_POST); PHP: