Re: QuickForm::addRule in groups
| From: | Wolfram Kriesing | Date: | Tue, 08 Apr 2003 14:09:10 +0000 |
| Subject: | Re: QuickForm::addRule in groups | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-15028@lists.php.net to get a copy of this message | ||
thanks Bertrand.
cas 1) is just what i am doing
but i think i still have a prob :-(
i do the following
$group = array();
$group[0] =& HTML_QuickForm::createElement('html','Please....');
$group[1] =&
HTML_QuickForm::createElement('textarea','newData[comment]');
$group[1]->setRows(10);
$group[1]->setCols(60);
$group[1]->setValue(@$data['comment']);
$el =& $form->addGroup($group,null,'Comment');
$rule[0][1] = array('Please provide the comment!', 'required');
$form->addGroupRule($el->getName(),$rule);
but the renderer::renderElement() doesnt tell me it's required.
and i looked into group.php and the method
HTML_QuickForm/group::accept()
doesnt say it is required, so when calling
$element->accept($renderer, $required);
it doesnt pass the $required is false :-(
am i doing something wrong?
thanks
Bertrand Mansion wrote:
<wolfram@visionp.de> wrote :-- Wolfram ... opensource @ vision:produktion ... http://opensource.visionp.de ... translating template engine .... http://sf.net/projects/simpletpl ... authentication system .... http://sf.net/projects/authif i add a rule for an element in a group, the _required is not passed on to the group, am i right? therefore the renderer doesnt see that the element (in the group) is required I am using the latest CVS version (which becomes v3, I guess)I am posting a small example to show how rules work. First, you create the group: $group[0] =& HTML_QuickForm::createElement('html','info text'); $group[1] =& HTML_QuickForm::createElement('textarea','input','input'); $form->addGroup($group, 'mygroup', 'Group Label:'); (pay attention to the & in front of HTML_QuickForm::createElement) (don't forget to add your group to the form with addGroup and give it a name). Then, you can choose the way your group is required: 1. have only one element in the group required and you specify which one $rule[0][0] = array('This is required', 'required'); $form->addGroupRule('mygroup', $rule); We took 0 as an index because it's the name you gave to the element index in $group array. It could have been an associative array too for better readability. 2. have two elements required by specifying which ones $rule[0][0] = array('This is required', 'required'); $rule[1][0] = array('This is required', 'required'); $form->addGroupRule('mygroup', $rule) 3. have at least one of the elements required without specifying which one $form->addGroupRule('mygroup', 'At least one is required', 'required', null, 1); 4. have the whole group required as if it were an element $form->addGroupRule('mygroup', 'All fields are required', 'required'); When you deal with a group, it's recommended to use addGroupRule() because it offers more options. Good luck, Bertrand Mansion Mamasami.e. this $group[0] = HTML_QuickForm::createElement('html','info text'); $group[1] = HTML_QuickForm::createElement('textarea','input','input'); $form->addRule($group[1]->getName(),'This is required!','required'); and in the Renderer (i use an customized version of the Default-Renderer) renderElement() doesnt get the paramter $required=true passed to it. I think the bug is in QuickForm::addRule()if ($type == 'required' || $type == 'uploadedfile') { $this->_required[] = $element; }should beif ($type == 'required' || $type == 'uploadedfile') {if ($this->isInGroup($element)) {$groupName = $this->getGroup($element);$this->_group[$groupName]->setRequired($element);} else { $this->_required[] = $element; } }i am not an QuickForm-Expert. And i dont know if there are methods such as isInGroup() getGroup() etc. What do you say?