Re: QF, setting textarea value(?)

From: Date: Mon, 06 Oct 2003 09:32:51 +0000
Subject: Re: QF, setting textarea value(?)
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-8287@lists.php.net to get a copy of this message
<marba126@student.liu.se> wrote : > Thanks Bertrand, think you got me onto the right track! (This resulted in a > thougt about the HTML_QF_Page::setConstants(), see the last rows.) > > I've just realized I left out some (most likely) highly relevant information > in my first description of the problem. Using HTML_QF->setConstants() will > most probably do the trick if the form is created with the QF-package only. > However this isn't actually true in my case. The form I use is bulit with > the QF_Controller-package. > > I perform the reloading of my page (named "text_page") by pushing the button > generated on the line... > $this->addElement('submit', $this->getButtonName('text_page'), > 'Append > file to text'); > ...in the text_page's class extending class HTML_QF_Page. > > Clicking that submit button fires a "Direct"-action defined by: > $my_multi_page_form->addAction('text_page', new > HTML_QF_Action_Direct()); > > After some serious investigations of the QF_Controller-package's code ... > Using the 'direct'-action internally results in a 'jump'-action. This in > turn results in new header information being sent which makes a new request > to 'display' the text_page (reload it). Thus using HTML_QF::setConstants() > won't work because the constants ain't saved in the $_SESSION variable till > the 'display'-request. > > Nonetheless, it works using HTML_QF_Controller::setConstants() which do save > the constants in the $_SESSION variable. BUT there is a drawback with the > use of HTML_QF_Controller::setConstants() - I must unset it every time I > don't upload the text file because I still want to be able to edit the text. > Guess I've to that "manually" because there isn't any unsetConstants(), is > it? > > Or I have to use a customized action that make use of the > HTML_QF_Action_Display directly. Haven't tried of this variant yet. > > > Phu... Hope you got an idea of the problem otherwise please feel free to ask > for a better explanation. That would certainley be motivated ;) > > Finally, two ideas: > > 1. What do you think about overriding the setConstants() (inherited from > HTML_QF) in class HTML_QF_Page with something like: > function setConstants($constantValues, $filters=null) { > HTML_QuickForm::setConstants($constantValues, $filters=null); > $this->controller->setConstants($constantValues); > } > This would make setConstant() to always put the values into the (persistant) > $_SESSION variable. Well, I know you generally recommend using the > HTML_QF_Controller::setDefaults() for the sake of makeing a single-page form > look alike, but anyway... > > 2. Some kind of updateSubmitValues() method would be useful, at least in > this case (but maybe in other cases too). This would override both submitted > and default values but not constant values. Maybe this can already be done > with som filter-funtionallity? As you want to change the value of an element (your textarea) with the content of another element (your uploaded file), I suggest acting directly on the container values ($controller->container()), which references element values such as stored in the session. 1. Have a special index in the container called ['uploads'] 2. If an upload is done, store a reference to the uploaded file in this 'uploads' array. 3. Check if this array is empty or not. 4. If it's not empty, change the value of the container for your textarea element. Do all this in your action class. I will make an example for that and other stuff like uploading images and changing the content of a page based on the content of another page this week. It will probably be available in CVS this week. Bertrand Mansion Mamasam

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