View Single Post
  #1 (permalink)  
Old 04-10-2008, 10:59 AM
MiK MiK is offline
Junior Member
 
Join Date: Mar 2008
Location: Ancona, Italy
Posts: 21
Send a message via MSN to MiK
Default Zend_Form_Element_Checkbox issue?

Hello to all..

I'm using ZF version 1.5.1 and I'm trying to create a single checkbox (with unchecked starting value) using the following code in my controller:

PHP Code:
$form = new Zend_Form();

$check = new Zend_Form_Element_Checkbox('check');
$check->setLabel('test')
      ->
setChecked(false)
      ->
setDecorators(array(
          
'ViewHelper'
      
));

$form->addElement($check);

echo 
$form->render(); 
which produces the following HTML code:
HTML Code:
<form enctype="application/x-www-form-urlencoded" action="" method="post">
   <dl class="zend_form">
      <input type="hidden" name="check" value="0" />
      <input type="checkbox" name="check" id="check" value="1" checked="checked"  checked="" />
   </dl>
</form>
The checkbox generated markup is wrong (note the duplicate 'checked' attribute) and the browser will ever set the checkbox to CHECKED state, and
i've found no way to get past this behaviour.

Another strange thing:
I wasn't able to find the point where the ZF creates the markup for that field.
I though it was in the view helper (Zend/View/Helpers/formCheckbox.php) which in fact contains the html part, but edits to this file don't make any change like it was not used..

Is this an issue or i didn't understand anything about ZF ?

Hope you get the point!
(sorry for any mistake, i'm not an english-native speaker)

Thanks.
Reply With Quote