Re: QuickForm_Controller: value set but blank field anyway!?

From: Date: Wed, 02 Mar 2005 12:13:30 +0000
Subject: Re: QuickForm_Controller: value set but blank field anyway!?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17786@lists.php.net to get a copy of this message
Patrick Fehr wrote: > Hi all > > I've gone through it several times, but I don't get wiser: > > PROBLEM: I have a QuickFormController Wizard of 2 Pages, very simple, see > below, what I want is that the value entered in the first Page gets > brought to the second page via Session, that works, in the class > PageSecond it's all ok. But then when displaying the form, the field on > the second page remains empty and I just can't find out why. > The code uses no special classes, so you could also copy it and try it on > your server, mine runs with php5.0.0 sessions enabled, html_quickform is > version 1.0.4 > > The funny thing: Once written, the value entered in PageFirst remains > there(probably because of the session that started). > > I thank you for your consideration, this project is really important to > me, I just don't understand, what I am doing wrong or is it a server sided > problem? > I have the php-specs here: http://www.idance.ch/info.php > > REMARKS: > > Could it have something to do with the GET_string ?_qf_page2_display=true > that get's added to the url? > > code: > --------------------->8------------------------ > <?php > include 'inc/config.php'; > > require_once 'HTML/QuickForm/Controller.php'; > require_once 'HTML/QuickForm/Action/Next.php'; > require_once 'HTML/QuickForm/Action/Back.php'; > require_once 'HTML/QuickForm/Action/Display.php'; > > session_start(); > > class PageFirst extends HTML_QuickForm_Page > { > function buildForm() > { > $this->_formBuilt = true; > > $this->addElement('header', null, 'Wizard page 1 of 2'); > > $this->_name = $this->addElement('text', 'last', > 'First Input:', > null, array('size' => 30)); > > $prevnext[] = $this->createElement('submit', > $this->getButtonName('back'), '<< Back'); > $prevnext[] = $this->createElement('submit', > $this->getButtonName('next'), 'Next >>'); > $this->addGroup($prevnext, null, '', '&nbsp;', false); > > $this->addGroupRule('name', array('last' => > array(array('Last name > is required', 'required')))); > > $this->setDefaultAction('next'); > } > } > > class PageSecond extends HTML_QuickForm_Page { > var $_name; > function buildForm() > { > $this->_formBuilt = true; > > //getting the values from the $_SESSION: > $data = $this->controller->container(); > > $this->addElement('header', null, 'Wizard page 2 of 2'); > > $this->_name = $this->addElement('text', 'last2', > 'Should have > the > value of page1 in it:', null, array('size' => 30)); > > //the following works!(checked with getValue() and isFrozen() ): > > $this->_name->setValue($data['values']['page1']['last']); > $this->_name->freeze(); > > $prevnext[] =& $this->createElement('submit', > $this->getButtonName('back'), '<< Back'); > $prevnext[] =& $this->createElement('submit', > $this->getButtonName('next'), 'Finish'); > $this->addGroup($prevnext, null, '', '&nbsp;', false); > > $this->setDefaultAction('next'); > } > } > > class ActionProcess extends HTML_QuickForm_Action > { > function perform(&$page, $actionName) > { > echo "Submit successful!<br>\n<pre>\n"; > var_dump($page->controller->exportValues()); > echo "\n</pre>\n"; > } > } > > $wizard =& new HTML_QuickForm_Controller('Wizard'); > $wizard->addPage(new PageFirst('page1')); > $wizard->addPage(new PageSecond('page2')); > > // We actually add these handlers here for the sake of example > // They can be automatically loaded and added by the controller > $wizard->addAction('display', new HTML_QuickForm_Action_Display()); > $wizard->addAction('next', new HTML_QuickForm_Action_Next()); > $wizard->addAction('back', new HTML_QuickForm_Action_Back()); > > // This is the action we should always define ourselves > $wizard->addAction('process', new ActionProcess()); > > $wizard->run(); > ?> > -------------------------8<------------------------------- > > I found it out: had to $a_valname =& $this->addElement('text', 'last', 'First Input:', null, array('size' => 30)); meaning add the element as a reference, yeah makes sense now. Thanks for using this newsgroup as my think-tank *lol :) well, maybe this helps someone else, anyway Patrick -- Patrick Fehr Swiss Federal Institute Of Technology

« previous php.pear.general (#17786) next »