Antonio,

I forgot that if you use the same decorator twice you have to name it or
else it will get overwritten:


       $this->setDecorators(array(
               'FormElements',
               array(array('innerDlTag' => 'HtmlTag'), array('tag' =>
'dl')),
               array('FormErrors', array(
                       'placement' => 'prepend',
                       'markupListStart' => '<div class="msg msg-error">',
                       'markupListEnd' => '</div>',
                       'markupListItemStart' => '<p>',
                       'markupListItemEnd' => '</p>',
               )),
               array(array('outerDivTag' => 'HtmlTag'), array('tag' =>
'div', 'class' => 'inner-form')),
               array('Form', array('class' => 'basic'))
       ));

That should fix the missing DL tag.

As far as the errors go, if you're using Zend_Form how intended, you should
never have to set the errors. Instead rely on the Form to validate the
values via $form->isValid($_POST). If the form is not valid, the errors will
be automatically set.

Konr

------ Posting private response back to list -----

Hi Konr Ness,
thanks for your help but the form's output is still wrong.

I notice that the last "HtmlTag" decorator (div) overwrite the first (dl).
Besides, I try to set errors to the form using $form->setErrors(array('an
error message')) but that error are not rendered.


This is the listing of Zend_Form Class

<?php
/**
 * Core_Form_Admin_Login
 *
 * @category   Core
 * @package    Core_Form
 */
class Core_Form_Admin_Login extends Zend_Form {

       private $_standardElementDecorator = array(

       'ViewHelper',
       array('HtmlTag', array('tag' => 'dd')),
               'Errors',
       array('Label', array('tag' => 'dt'))
    );

    protected $_buttonElementDecorator = array(
               'ViewHelper',
       array('HtmlTag', array('tag' => 'dd')),
       array('Label', array('tag' => 'dt', 'style' => 'visibility:hidden;'))
    );


   public function init() {
       $this->setMethod('post');
       $this->setAction('/admin/
core/utenti/admin-login');



       $username = new Zend_Form_Element_Text('username');
       $username->setFilters(array('StringTrim', 'StringToLower'))
                        ->setLabel('Username:')
                        ->setRequired(true)
                        ->setDecorators($this->_standardElementDecorator)
                        ->setAttrib('class', 'txt');


       $password = new Zend_Form_Element_Password('password');
       $password->setFilters(array('StringTrim'))
                        ->setLabel('Password:')
                        ->setRequired(true)
                        ->setDecorators($this->_standardElementDecorator)
                        ->setAttrib('class', 'txt');


       $submit = new Zend_Form_Element_Submit('accedi');
       $submit->setLabel('Accedi')
                  ->setIgnore(true)
                  ->setDecorators($this->_buttonElementDecorator)
                        ->setAttrib('class', 'button');


       $this->addElements(array($username, $password, $submit));


       $this->setDecorators(array(
               'FormElements',
               array('HtmlTag', array('tag' => 'dl')),
               array('FormErrors', array(
                       'placement' => 'prepend',
                       'markupListStart' => '<div class="msg msg-error">',
                       'markupListEnd' => '</div>',
                       'markupListItemStart' => '<p>',
                       'markupListItemEnd' => '</p>',
               )),
               array('HtmlTag', array('tag' => 'div', 'class' =>
'inner-form')),
               array('Form', array('class' => 'basic'))
       ));

       }
}
?>

--------------------------------------------------
HTML i get is:
--------------------------------------------------

<form class="basic" enctype="application/x-www-form-urlencoded"
method="post" action="/admin/core/utenti/admin-login">

<div class="inner-form">
 <dt id="username-label">
   <label for="username" class="required">Username:</label>
 </dt>
 <dd>
   <input type="text" name="username" id="username" class="txt">
 </dd>

 <dt id="password-label">
   <label for="password" class="required">Password:</label>
 </dt>
 <dd>
   <input type="password" name="password" id="password" class="txt">
 </dd>

 <dt id="accedi-label">
   <label for="accedi" style="visibility:hidden;"
class="optional">Accedi</label>
 </dt>
 <dd>
   <input type="submit" name="accedi" id="accedi" value="Accedi"
class="button">
 </dd>
</div>

</form>


Thanks again.
Antonio


On Tue, Jan 19, 2010 at 10:52 PM, Konr Ness <[email protected]> wrote:

> I haven't tested this for validity, but it should be something like:
>
>
> $this->setDecorators(array(
>     'FormElements',
>     array('HtmlTag', array('tag' => 'dl')),
>     array('FormErrors', array(
>         'placement' => 'prepend',
>         'markupListStart' => '<div class="msg msg-error">',
>         'markupListEnd' => '</div>',
>         'markupListItemStart' => '<p>',
>         'markupListItemEnd' => '</p>',
>     )),
>     array('HtmlTag', array('tag' => 'div', 'class' => 'inner-form')),
>
>     array('Form', array('class' => 'basic'))
> ));
>
> If that still isn't right, please post the code you've got so far and the
> HTML output that you are getting.
>
> Konr Ness
>
>
> On Tue, Jan 19, 2010 at 11:57 AM, <[email protected]> wrote:
>
>> I would like to get a similar form:
>>
>> <form enctype="multipart/form-data" method="post" action="" class="basic">
>>   <div class="inner-form">
>>      <div class="msg msg-error"><p>I'm an error message!</p></div>
>>      <dl>
>>         <dt><label for="some1">Username:</label></dt>
>>         <dd>
>>            <input type="text" name="some1" id="some1" class="txt"/>
>>         </dd>
>>
>>         <dt><label for="some3">Password:</label></dt>
>>         <dd>
>>            <input type="text" name="some3" id="some3" class="txt"/>
>>         </dd>
>>
>>         <dt></dt>
>>         <dd>
>>            <input type="submit" value="Log in" class="button"/>
>>         </dd>
>>      </dl>
>>   </div>
>> </form>
>>
>>
>> --------------------------------------------------------------------
>> How do i get it with Decorators? I try with the following code but
>> something still missing:
>>
>>  1. <div class="inner-form"> - that wraps all elements inside the form.
>>  2. <div class="msg msg-error"><p>I'm an error message!</p></div> - error
>> message.
>> --------------------------------------------------------------------
>>
>> <?php
>>
>> class Core_Form_Utenti_Login extends Zend_Form {
>>
>>     protected $_standardElementDecorator = array(
>>        'ViewHelper',
>>        array('HtmlTag', array('tag' => 'dd')),
>>                'Errors',
>>        array('Label', array('tag' => 'dt'))
>>     );
>>
>>     protected $_buttonElementDecorator = array(
>>                'ViewHelper',
>>        array('HtmlTag', array('tag' => 'dd')),
>>        'Label'
>>     );
>>
>>
>>    public function init() {
>>
>>        $username = new Zend_Form_Element_Text('username');
>>        $username->setFilters(array('StringTrim', 'StringToLower'))
>>                         ->setLabel('Username:')
>>                         ->setRequired(true)
>>                         ->setDecorators($this->_standardElementDecorator)
>>                         ->setAttrib('class', 'txt');
>>
>>        $password = new Zend_Form_Element_Password('password');
>>        $password->setFilters(array('StringTrim'))
>>                         ->setLabel('Password:')
>>                         ->setRequired(true)
>>                         ->setDecorators($this->_standardElementDecorator)
>>                         ->setAttrib('class', 'txt');
>>
>>        $submit = new Zend_Form_Element_Submit('accedi');
>>        $submit->setLabel('Accedi')
>>                   ->setIgnore(true)
>>                   ->setDecorators($this->_buttonElementDecorator)
>>                         ->setAttrib('class', 'button');
>>
>>        $this->addElements(array($username, $password, $submit));
>>
>>                $this->setDecorators(array(
>>                        'FormElements',
>>                        array('HtmlTag', array('tag' => 'dl')),
>>                        array('Description', array('placement' =>
>> 'prepend', 'class' => 'error')),
>>                        array('Form', array('class' => 'basic'))
>>                ));
>>        }
>> }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>

Reply via email to