Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

All radioButtons checked while one is supposed to only

Im definiing radio group:

    $a = new \Phalcon\Forms\Element\Radio('prepaytype_a', array('name' => 'prepaytype'));
    $a->setAttribute('checked', 'checked');

    $b = new \Phalcon\Forms\Element\Radio('prepaytype_b', array('name' => 'prepaytype'));

but they gets rendered like that:

<input type="radio" checked="checked" value="1" name="prepaytype" id="prepaytype_a">

<input type="radio" checked="checked" value="2" name="prepaytype" id="prepaytype_b">

while only the first should be checked.


why is that ?



value for both radiobuttons. If I select A, I want to get 1, if I select B, I want to get 2.

How do you render the objects?


i would do it:

$a = new \Phalcon\Forms\Element\Radio('prepaytype_a', array('name' => 'prepaytype', 'value' => 1));
$b = new \Phalcon\Forms\Element\Radio('prepaytype_b', array('name' => 'prepaytype', 'value' => 2));

//and if you still need to go back to this form and you want to be same as user left it

if ($_POST['prepaytype'] == 1){

// OR 

$a = new \Phalcon\Forms\Element\Radio('prepaytype_a', [
    'name' => 'prepaytype',
    'value' => 1,
    'checked' => ($_POST['prepaytype'] == 1 ? 'checked' : false / or null i dont know )