views:

249

answers:

1

I am trying to create radio buttons with Zend Framework. This is the way I want to do it:

()Yes ()No John Smith
()Yes ()No Peter Fallon

I want to attach two radio buttons to one ID:

Thanks

Ok now I am getting how this works, thanks for your patience.

Well this is what I have.

class ListForm extends Zend_Form

{
public function __construct() { parent::__construct(); }

public function createForm(array $model,$checkedArr)
{
    // set the method for the display form to POST
    $this->setMethod('post');
$this->setAction('/List/inputform');

    // add an check box element        
$check = new Zend_Form_Element_MultiCheckbox('check');

foreach ($model as $option) {      
   $check->addMultiOption($option['id'],.$option['name'].' '.$option['lname']); 
}

// Add a checkmark to the check box.
$check->setValue($checkedArr); 

    // add the submit button
    $submit = new Zend_Form_Element_Submit('submit'); 
    $submit->setLabel('Submit'); 
    $submit->setValue('submit');

    return  $this->addElements(array($check,$submit));
}}

Then I insert this form into the view

$this->view->form = $form->createForm($model,$array);

By doing this a list of people gets created with a checkbox

[] John Smith

[] Peter Fallon

What I want to do is to change from a checkbox to a two radio buttons, like this

()Yes ()No John Smith

()Yes ()No Peter Fallon

So when the form gets delivered to the Action function on the Controller I can loop trough all the list and determine which one has a Yes selected and which one has a No selected.

I hope that this is more clear.

+1  A: 

well ok, please provide the code you've written so far! it will be much easier to help then!

In general, everything is explained in the Zend_Form manual. I assume you generaly know how to add form elements to a Zend Form. Here you see what options you have for the Radio Button.

And this is an example of how it could look like:

$gender = new Zend_Form_Element_Radio('gender');
$gender->setLabel('Gender:')
    ->addMultiOptions(array(
     'male' => 'Male',
     'female' => 'Female'
    ))
    ->setSeparator('|');
tharkun
Thanks for your reply, I have the same