-- devxtech <[EMAIL PROTECTED]> wrote
(on Friday, 26 September 2008, 01:43 PM -0700):
> 
> After looking through the mailing list archives and trying a lot of different
> things I can't seem to find out why the form elements won't display from my
> viewscript. They display fine when i don't use a viewscript and use the
> default decorators.

Make sure that you call setView() on the elements. Easiest would be to
do the following at the top of your view script:

    foreach ($this->element as $item) {
        $item->setView($this);
    }


> My viewscript (/application/views/scripts/contactForm.phtml) looks like
> this:
> 
> <h4>Please Fill Me Out</h4>
> <form action="<? $this->escape($this->element->getAction()); ?>" method="<?
> $this->escape($this->element->getMethod());?>">
> <fieldset>
> <legend>Contact Information</legend>
> <p>Please provide us with the following information so we may contact
> you.</p>
> <? $this->element->firstName; ?>
> <? $this->element->lastName; ?>               
> <? $this->element->email; ?>
> <? $this->element->telephoneNum; ?>
> </fieldset>
> <fieldset>
> <legend>Contact Reason & Message</legend>
> <p>Now please provide us with your reason for contacting us and a brief
> message.</p>
> <? $this->element->contactReason; ?>
> <? $this->element->message; ?>
> </fieldset>
> <? $this->element->submit; ?>
> </form>
> 
> My class in (/application/forms/ContactForm.php) is as follows:
> 
> class forms_ContactForm extends Zend_Form {
>       public function __construct($options = null)
>       {
>               parent::__construct($options);
>               $this->setAction('');
>               $this->setMethod('post');
>               $this->setName('contact_us');
>               
>               $firstName = new Zend_Form_Element_Text('firstName');
>               $firstName->setLabel('First Name')
>                                 ->setRequired(true)
>                                 ->addValidator('NotEmpty', true)
>                                 ->addValidator('Alpha', true);
>               
>               $lastName = new Zend_Form_Element_Text('lastName');
>               $lastName->setLabel('Last Name')
>                                ->setRequired(true)
>                                ->addValidator('NotEmpty')
>                                ->addValidator('Alpha', true);
>                                
>               $telephoneNum = new Zend_Form_Element_Text('telephoneNum');
>               $telephoneNum->setLabel('Telephone Number')
>                                        //->setDescription('example 
> (555)555-5555')
>                                        ->setRequired(false)
>                                        ->addValidator('NonEmpty');
>                                
>               $email = new Zend_Form_Element_Text('email');
>               $email->setLabel('Email Address')
>                         ->addFilter('StripTags')
>                         ->addFilter('StringTrim')
>                         ->addFilter('StringToLower')
>                         ->setRequired(true)
>                         ->addValidator('NotEmpty', true)
>                         ->addValidator('EmailAddress');
>                         
>               $contactReason = new Zend_Form_Element_Select('contactReason');
>               $contactReason->setLabel('Reason for Contact')
>                                         ->setRequired(true)
>                                         ->addMultiOption('none','Please 
> Select One')
>                                         
> ->addMultiOption('personal','Personal')
>                                         
> ->addMultiOption('business','Business')
>                                         ->addValidator('NotEmpty');
>               
>               $message = new Zend_Form_Element_Textarea('message');
>               $message->setLabel('Comments')
>                               ->setAttrib('rows','15')
>                               ->setAttrib('cols','70')
>                               ->setRequired(true)
>                               ->addValidator('NotEmpty');
>                               
>               $submit = new Zend_Form_Element_Submit('submit');
>               $submit->setLabel('Submit Form');
>               
>               $this->setDecorators(array(
>                       array('ViewScript',array('viewScript' => 
> 'forms/contactForm.phtml'))
>               ));
>               
>               $this->addElements(array($firstName, $lastName, $email, 
> $telephoneNum,
> $contactReason, $message, $submit));
>       }
> }
> ?>
> 
> 
> When the script runs it outputs the fieldsets and the legends with the
> descriptions but nothing else is outputted. Any ideas on what could be
> causing this. Been trying to figure this out for a few days now and could
> really use some help as I'm still learning OOP and the Zend Framework.
> -- 
> View this message in context: 
> http://www.nabble.com/Zend_Form-ViewScript-Elements-don%27t-show-tp19696062p19696062.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/

Reply via email to