Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-10-2008, 10:59 AM
MiK MiK is offline
Junior Member
 
Join Date: Mar 2008
Location: Ancona, Italy
Posts: 17
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 01:49 PM
Drakos7's Avatar
Junior Member
 
Join Date: May 2007
Location: MD, USA, Terra, Sol
Posts: 5
Default

I ran into something similar. IIRC you need to do it this way
PHP Code:
->setCheckedValue(true)  //whatever value you want to send when checked, could be a string
->setValue(false)        //the current value of the checkbox 
To find the code you need to look in Zend/Form/Element and Zend/Form/Decorator.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 02:03 PM
MiK MiK is offline
Junior Member
 
Join Date: Mar 2008
Location: Ancona, Italy
Posts: 17
Send a message via MSN to MiK
Default

Thanks for your reply.

I tried to do that, but nothing changes.
The markup generated is still the same, and the browser refuses to uncheck the
checkbox by default.

This is driving me nuts, but for the moment i arranged the thing using Yes/No select boxes...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:00 PM.