-- maxarbos <[EMAIL PROTECTED]> wrote
(on Tuesday, 01 July 2008, 10:10 AM -0700):
>
>
>
> Matthew Weier O'Phinney-3 wrote:
> >
> >>
> >> The TestingForm.php is built as such:
> >> TestForm extends Zend_Form {
> >> public function __construct($options=null) {
> >> parent::__construct($options);
> >>
> >> $this->setAttrib('accept-charset', 'UTF-8');
> >> }
> >
> > I'd place the above in setAttrib() call as the first call in your init()
> > method below, and get rid of __construct() entirely.
> >
> >> public function init() {
> >> $name = $this->addElement('text', 'name', array().....);
> >> }
> >>
> >> }
> >>
> >>
> >
>
> I left out that we are also including :
>
> $this->setDecorators(array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
> array('Description', array('placement' => 'prepend')),
> 'Form'
> ));
>
> in the __construct, but moving this all to the init() doesnt seem to load
> the decorators in time.
It _should_ work... there's a test for exactly that situation in the
testbed. If it's not working, post the simplest possible use case where
it fails to the tracker so I can try and verify.
> Matthew Weier O'Phinney-3 wrote:
> >
> >> 2) I want to be able to add elements dynamically to the form depending
> >> on a
> >> result set of data from the db.
> >>
> >> Say a person has 4 children, I want to dynamically add four text elements
> >> to
> >> the form, one for each record retrieved from the db.
> >>
> >> How can I do this with my setup?
> >
> > Yes. Create an element for each child, and attach each with a different
> > form element name:
> >
> > foreach ($children as $key => $child) {
> > $form->addElement('text', 'child' . $key, array('value' =>
> > $child'));
> > }
> >
> >
>
> I was pretty much doing the same things, but included
> foreach($children as $key=>$val){
> $field.$key = $this->addElement('text', 'fieldname'.$key, etc....)
>
> $group[]='fieldname'.$key;
> }
>
> $this->addDisplayGroup(
> $number_group, 'groupname' ....)
>
>
> and ended up getting error of:
>
> 'No valid elements specified for display group'
>
>
> So once I got rid of the '$field.$key =' it all worked correctly.
>
>
> Do you have any other updated resources for best practices or structure of a
> large site using this framework?
>
> thanks.
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Form-%3A-Subforms%2C-dynamic-element-creation-and-best-practices-tp18203896p18220883.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/