TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Troubles with sessions (Kohana 3.0.12)
  • I'm having troubles with sessions in Kohana.

    I want to make a 'multi-page' form. Betwees pages i wanted to store the data from the previous forms in sessions to be used and saved at the end. But the session key's dissapear each time.

    $content = View::factory('step1');
            $enrollment = ORM::factory('Enrollment');
            $session = Session::instance();
    
            $enrollments = $enrollment->find_all();
    
            $this->template->content = $content
            ->bind('enrollments', $enrollments);
    
    
            if($_POST){
                if (isset($_POST['action_parent']))
                    {
    
                        // Putting values in Session variables              
                        $_SESSION['parent_name'] = $_POST['parent_name'];
                        $_SESSION['parent_email'] = $_POST['parent_email'];
                        $_SESSION['parent_telephone'] = $_POST['parent_telephone'];
                        $_SESSION['parent_cellphone'] = $_POST['parent_cellphone'];
                        $_SESSION['parent_street'] = $_POST['parent_street'];
                        $_SESSION['parent_postalcode'] = $_POST['parent_postalcode'];
                        $_SESSION['parent_city'] = $_POST['parent_city'];
                        $_SESSION['childNumber'] = 1;
    
    
    
    
                        $this->template->content = View::factory('step2');
                        $_POST = null;
    
                    }
    
                if (isset($_POST['action_child_again']))
                    {
                        $childNumber = $_POST['childNumber'];
    
                        // Putting values in Session variables              
                        $_SESSION['child'.$childNumber.'_name'] = $_POST['child_name'];
                        $_SESSION['child'.$childNumber.'_dob'] = $_POST['child_dob'];
                        $_SESSION['child'.$childNumber.'_rrn'] = $_POST['child_rrn'];
                        $_SESSION['child'.$childNumber.'_inGroupWith'] = $_POST['child_inGroupWith'];
                        $_SESSION['child'.$childNumber.'_medicalInfo'] = $_POST['child_medicalInfo'];
    
                        $childNumber++;
                        $_SESSION['childNumber'] = $childNumber;
    
    
                        $this->template->content = View::factory('step2');
                        $_POST = null;
    
    
                    }
    
                if (isset($_POST['action_child_finish']))
                    {
                        $childNumber = $_POST['childNumber'];
    
                        // Putting values in Session variables  
                            // Parent values
                        $_SESSION['parent_name'] = $_POST['parent_name'];
                        $_SESSION['parent_email'] = $_POST['parent_email'];
                        $_SESSION['parent_telephone'] = $_POST['parent_telephone'];
                        $_SESSION['parent_cellphone'] = $_POST['parent_cellphone'];
                        $_SESSION['parent_street'] = $_POST['parent_street'];
                        $_SESSION['parent_postalcode'] = $_POST['parent_postalcode'];
                        $_SESSION['parent_city'] = $_POST['parent_city'];
    
    
                            // Child values                 
                        $_SESSION['child'.$childNumber.'_name'] = $_POST['child_name'];
                        $_SESSION['child'.$childNumber.'_dob'] = $_POST['child_dob'];
                        $_SESSION['child'.$childNumber.'_rrn'] = $_POST['child_rrn'];
                        $_SESSION['child'.$childNumber.'_inGroupWith'] = $_POST['child_inGroupWith'];
                        $_SESSION['child'.$childNumber.'_medicalInfo'] = $_POST['child_medicalInfo'];
    
                        $this->template->content = View::factory('step3');
                        $_POST = null;
    
    
                    }
    
    
                if (isset($_POST['action_enrollment']))
                    {
    
                        $_SESSION['parent_name'] = $_POST['parent_name'];
                        $_SESSION['parent_email'] = $_POST['parent_email'];
                        $_SESSION['parent_telephone'] = $_POST['parent_telephone'];
                        $_SESSION['parent_cellphone'] = $_POST['parent_cellphone'];
                        $_SESSION['parent_street'] = $_POST['parent_street'];
                        $_SESSION['parent_postalcode'] = $_POST['parent_postalcode'];
                        $_SESSION['parent_city'] = $_POST['parent_city'];
    
    
                        $_SESSION['childNumber'] = 1;
                        $childNumber = $_SESSION['childNumber'];
    
                        $_SESSION['child'.$childNumber.'_name'] = $_POST['child_name'];
                        $_SESSION['child'.$childNumber.'_dob'] = $_POST['child_dob'];
                        $_SESSION['child'.$childNumber.'_rrn'] = $_POST['child_rrn'];
                        $_SESSION['child'.$childNumber.'_inGroupWith'] = $_POST['child_inGroupWith'];
                        $_SESSION['child'.$childNumber.'_medicalInfo'] = $_POST['child_medicalInfo'];
    
    
    
    
                        $this->template->content = View::factory('step4');
                        $_POST = null;
    
    
                    }
    
            }
    
    

    Is there an other way to easily store this data? Could I make an object and store the data in this en always extend this object? Or do I really need to put the the sessions values in a POST value again to get them to the next step?

  • Use $session->set() not $_SESSION[]

  • so always $session->set($parent_name, $_POST['parent_name']) ? Or should i look at the Key as $session->set('parent_name', ...) ?

  • A bit more like this: $session->set('key', $this->request->post('key'));

    Reading the docs would help very much kohana/sessions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion