views:

1011

answers:

4

In my form i have this code;

// Add the submit button
$element = $this->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label' => 'Add new material'
));
$element->removeDecorator('label');

However the form still renders with the label element between the tags.

What am i doing wrong?

A: 

I think the argument to removeDecorator is case-sensitive. I.e., it should be "Label" # note the uppercase 'L'.

Noah

Noah
I tried that it doesn't make any difference.I found this in another answer, but it doesn't seem right to do it this way as it is not how the documentation descibes how to do it.$element->removeDecorator('DtDdWrapper')->addDecorator('HtmlTag', array('tag' => 'dd')); However, even removing the <dt> element from the html did not solve my overall issue of not being able to position the submit button hard to the left.
So, you changed this: $element->removeDecorator('label'); to this: $element->removeDecorator('Label'); and it still didn't work? If that's the case perhaps try var_dump(getDecorators()) and let's go from there.
Noah
+2  A: 

The function addElement returns a reference to the current form not to the last added element.

You could try this:

$form = new Zend_Form();
$form->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label'     => 'Add new material'
));

$element = $form->getElement('submit');
$element->removeDecorator('label');
Erik
AlsoZend_Db_Element has no function addElementZend_Db_Form has
Erik
A: 

To overcome this nuisance I'm defining manually the decorators for my element...

$details->addElement('text', 'in_year', array(
    'decorators'=>array(
    'ViewHelper',
    array('HtmlTag', array('tag' => 'span')),
    )
));

You can of course define your own tags. In this example I only initialise the "ViewHelper" decorator. If I want to initialise the "Label" decorator I would do:

$details->addElement('text', 'in_year', array(
    'decorators'=>array(
    'ViewHelper',
    'Label',
    array('HtmlTag', array('tag' => 'span')),
    ),
    'attribs' => array('class' => 'required validate-digits')
));

I hope this makes sense... :o)

AngelP
+1  A: 

This worked for me:

$this->addElements(array(  
  new Zend_Form_Element_Submit('submit', array(  
    'label' => 'Save'  
  ))  
));  
$element = $this->getElement('submit');  
$element->removeDecorator('DtDdWrapper');

I did print_r($element); to find out what decorators exist for $element.

jwhat