Re: About QuickForm validation
| From: | Alexey Borzov | Date: | Tue, 11 Nov 2003 12:22:56 +0000 |
| Subject: | Re: About QuickForm validation | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-23434@lists.php.net to get a copy of this message | ||
Hi!
Hodicska Gergely wrote:
Alexey mentioned to me: "validation in QuickForm validates not *elements* as a whole, but *values* of elements". But I think this concept could be not enough effective in some case. 1. In some situation it would be better, if an element could validate itself. Because the validation depends not only from the actual value of the element but from the actual state. For example I have an own elementtype, which need a quite huge initial data. Part of this is needed to the the validation. Now I can do something like this. $temp = &$form->addElement('type', 'name',...); $form->addRule('name',..., $temp->getValidationData(),...); But I don't like this, and is think it's not a good solution because of performance issues. The argument will passed by value. And I think this is unnecessary, bacause these data exist in the time of validation in the validated object.I tested a bit, and the following solution in 3.2 seems to work (assuming your element has a validate() method): $temp =& $form->addElement('type', 'name', ...); $form->addRule('name', 'This should be valid', 'callback', array(&$temp, 'validate')); The object will be passed by reference, thus no copying of data.