Re: Issus while updating from QF to QF2

From: Date: Tue, 14 Feb 2012 13:52:47 +0000
Subject: Re: Issus while updating from QF to QF2
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-31415@lists.php.net to get a copy of this message
Hi Olaf, On 13.02.2012 1:25, Olaf Gleba wrote:
i am currently updating my CMS form processing from QuickForm to QuickForm2. I got used to the new concept and vary syntax except two issues. 1. Adding/use rules with callbacks Searching for former posts on the list i found http://news.php.net/php.pear.general/31351 which seems to be similiar to my problem/question. I have a login page with a username and password form fields. While submitting the form i must supply both field values to a indepent class method. The method checks the database if the given combination fits. Returns false/true. On PasteBin there is a abstract of the current implementation [1]. Are there any example how to this within QuickForm2? Subclassing the factory Rule file is fine, but my knowledge is simply not well enough to do it without any docs or examples ;-)
I don't see any problems with directly porting your code. In fact, I was wrong in the linked answer when I said that it's impossible to access value of another element, as I missed an option of passing the element / its value as an additional argument to the callback. $email = $form->addElement(...); $password = $form->addElement(...); $password->addRule(
    'callback', gettext('Invalid password'),
    array(
        'callback' => array($LOGIN, 'testSecret'),
        'arguments' => array($email->getValue())
    )
);
2. The cms uses smarty. To leave the (smarty)templates as clean and small as possible, i currently inject a little helper template right before rendering the form to avoid putting the same declaration of<required> and/or<error> vars (and conditions) over and over on every form field within the smarty templates. This little template snippet [2] relies on the former func setRequiredTemplate(). Is there any complement for this function in QF2?
No, there's nothing similar it seems. Even port of ArraySmarty renderer [1] does not contain this method. Note, however: it was implemented in such a way that the template was re-parsed on outputting every required element, leading to major performance hit. Smarty now has macros (or template functions) it seems [2] and that's how I'd suggest to re-implement that. [1] http://pear.php.net/pepr/pepr-proposal-show.php?id=653 [2] http://www.smarty.net/docs/en/language.function.function.tpl
[1] http://pastebin.com/Np2BwFFi [2] http://pastebin.com/7Xmfj3Xr I am very grateful for some help on both topics! greets Olaf


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