I'm trying to populate a HTML form with data saved in session. This is what i've done so far but it's not working:
In my controller:
$sessionErrorForm = new Zend_Session_Namespace('errorForm');
$sessionErrorForm->prenom = $form['prenom'];
$this->_redirect('/inscription');
In my view, i need to display something in the value field if a session exists:
<div><input type="text" name="prenom" value="<?php if (isset($sessionErrorForm->prenom)): echo $sessionErrorForm->prenom; endif;?>" title="Prénom *"/>
Thanks in advance for your help
Ok. Same thing like here. You always have to instantiate your Session before you can access it. You can declare it in your controller:
$session = new Zend_Session_Namespace('errorForm');
$this->view->sessionErrorForm = $session;
And access it in your view with $this->sessionErrorForm
:
<div><input type="text" name="prenom" value="<?php if (isset($this->sessionErrorForm->prenom)): echo $this->sessionErrorForm->prenom; endif;?>" title="Prénom *"/>
Or you can declare it in your view and use it like the following:
<?php $sessionErrorForm = new Zend_Session_Namespace('errorForm'); ?>
<div><input type="text" name="prenom" value="<?php if (isset($sessionErrorForm->prenom)): echo $sessionErrorForm->prenom; endif;?>" title="Prénom *"/>
But nevertheless if you write into your session in a previous request you always have to create a new reference to your session, if you don't declare it in the scope before.