Re: QuickForm::addRule in groups

From: Date: Tue, 08 Apr 2003 16:10:10 +0000
Subject: Re: QuickForm::addRule in groups
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15043@lists.php.net to get a copy of this message
<wolfram@visionp.de> wrote : > Bertrand Mansion wrote: >> <wolfram@visionp.de> wrote : >> >> >>> 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'); >> >> >> First, why don't you use directly this : >> >> $form->addElement('textarea', 'newData[comment]', >> 'Please....', array('rows' >> => 10, 'cols' => 60)); > > yeah ok. > >> BTW, use setDefaults() if your $data['comment'] value is supposed to be the >> default value of your textarea: >> >> $form->setDefaults(array('newData[comment]' => >> $newData['comment'])); >> >> There is no need to use setDefault if it's the submitted value as it is >> automatically retrieved. So just don't specify a value. > > ok, i didnt think of that > >>> $rule[0][1] = array('Please provide the comment!', 'required'); >>> $form->addGroupRule($el->getName(),$rule); >> >> >> You MUST give your group a name. Do $form->addGroup($group, 'groupname', >> 'Comment'); and $form->addGroupRule('groupname', $rule); > > i didnt give it a name, because i didnt want this name around the > elements name. what a group names does is given the element the name: > groupName[elemenName] > can i prevent from doing that? Set appendName (last addGroup parameter) to false. >> But I don't see why you use a group in that case. > > actually just because i get the form via ->toHtml() > and the renderer built a table around it, so that the 'html'-element > is right above the textarea, it's just and additional info for the > textarea, which should be right at this spot > Should i do that differently? > May use the Array-Renderer and build the form in the template ... mmmh > i will think about it If this is only to add HTML, you can use setElementTemplate(). It's the easiest way to change an element template: $form->setElementTemplate('mytextarea', '<tr><td>{label}</td><td>Please....<br />{element}</td></tr>'); (add the required and error blocks accordingly, look at the default element template) If the template you are using is ITX or Sigma, I would recommend you wait for the beta release 3.0 coming tonight or tomorrow. If you are using another template engine (Xipe ?), I would recommend you have a look at the two renderers that will be available tomorrow for ITX and Sigma and write a renderer for Xipe :) Alexey and I can probably help you with that, it's quite easy. The renderers will free you from having to deal with html in your PHP code. Whatever solution you use, it's not a good idea to add an html element in your group. >> Groups are here for logical reasons, not for presentation or layout reasons. >> >> You can have a look at the different examples in the docs/ directory. >> Example7 deals with grouped elements. > > ok, thanks a lot

« previous php.pear.dev (#15043) next »