Search code examples
phpzend-frameworkzend-formzend-form-element

store posted variables from a form long time


I have a form which is passing a number array like (56,78,98). I have stored that array in a variable called $array.

eg:

if(isset($_POST['submit']))
 {
 $checkbox_values=$_POST['checkbox_values];
$array= implode(',',$checkbox_values);
 }

$_POST['checkbox_values] is values of check boxes from a form.

I need to retrieve value of $array after the if(isset($_POST['submit'])) condition. I am using zend frame work. How can I use $array after if condition? or how can I use session or cookie in zend?

Thanks!!!


Solution

  • you could assign the array directly to the session using Zend_Session_Namespace:

    //you can initialize the session namespace almost anywhere.
    $session = new Zend_Session_Namespace('form')
    if(isset($_POST['submit'])) {
        $checkbox_values=$_POST['checkbox_values'];
        //will assign values to session namespace 'form' as key 'checkbox_values' as an array
        //session namespace will also accept objects and scalar values.
        $session->checkbox_values = implode(',', $checkbox_values);
        //$array= implode(',',$checkbox_values);
     }
    

    you can use the array any way you choose. You can pass it to the view...
    $this->view->checkboxValues = $session->checkbox_values;

    or you can pass it to your favorite model, what ever you need to do you can do. the session will remain until you unset it or overwrite it.

    Good Luck.