Re: [QuickForm] How should i use applyFilter()

From: Date: Thu, 30 May 2002 09:30:53 +0000
Subject: Re: [QuickForm] How should i use applyFilter()
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1515@lists.php.net to get a copy of this message
le 29/05/02 23:33, Wojciech Gdela à eltehaem@poczta.onet.pl a écrit : > Bertrand Mansion wrote: > >> $form = new HTML QuickForm('frmTest', 'GET'); >> >> $form->addElement('text', 'itxtTest', 'Test Text:'); >> $form->addElement('submit', 'submit', 'submit'); >> $form->addRule('itxtTest', 'Test text is required', >> 'required'); >> $form->applyFilter('__ALL__', 'trim'); >> >> if ($form->validate()) { >> $form->freeze(); >> echo 'Before filter:<pre>'; >> echo $form->getElementValue('itxtTest'); >> echo '</pre>'; >> echo 'After filter:<pre>'; >> var dump($form->_submitValues['itxtTest']); >> echo '</pre>'; >> } >> $form->display(); > > Aren't variables prepended with underscore (_) marked private? This is true. My mistake, I took a shortcut. I usually override the process() method to get submitted values. To do that, I use this code : function process() { $values = $this->_submitValues; while(list($k, $v) = each($values)) { if (is_string($val)) $val = addslashes($val); $cleanValues[$key] = $val; } return $cleanValues; } > Also when i type into text field "Foo'Bla" i will get (because of > magic_quotes_gpc setting): In your case, (use of magic_quotes_gpc is not recommended anyway), you can remove the slashes by using stripslashes instead of addslashes in the above code. > echo $form->_submitValues['itxtTest']; // == Foo\'Bla > > and (because of stripslashes along the code): > > echo $form->getElementValue('itxtTest'); // == Foo'Bla > > I like the second one. Using or not magic_quotes_gpc is user's choice so we won't deal with this issue. _submitValues contains the submitted values after they have been filtered. getElementValue returns the value of the element as it was submitted by the form before being filtered. I think this distinction can be useful. So I would consider keeping it if you don't mind. But I think we miss a method to access the submitted and filtered values. What do you think of a getSubmitValue($elementName) method ? Or maybe just add a parameter to getElementValue to say if we want the value before or after it has been filtered, with default being after ? Option 2 is better IMO. Still, note that the process() method is here to do the job. Thanks for your feedback, Bertrand Mansion Mamasam

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