Radio buttons in Form

I want to know if anyone have used radio button in form/volt, and how to assign model data to form for radio button as pre-set value. I have done for radio rendering

In form

$radio1 = new Radio("brand1", ['name'=>'type', 'value'=>3]);
$radio1->setLabel('brand1');

$radio2    = new Radio("brand2", ['name'=>'type', 'value'=>4]);
$radio2->setLabel('brand2');

$this->add($radio1);
$this->add($radio2);

in volt

<label class="radio-inline">
{{ form.render('radio1') }}
{{ form.label('radio1') }}
</label>
<label class="radio-inline">
{{ form.render('radio2') }}
{{ form.label('radio2') }}
</label>

so if model data $robot has default type of brand1, but how to assign the value to form and render it by the entity?

$robot = Robots::findFirst();
$form = new Form($robot);

You can bind the submission data to entity by: $form->bind($this->request->getPost(), $modelentity); Note: the name of radio element must be match with the name of the field in modelentity. In your case, the name of the radio element is "type" and you must sure "type" is the property of your model_entity



5.8k

Thanks for reply, I have found another soution in the forum, which is this, https://forum.phalconphp.com/discussion/7471/radio-group#C25629

You can bind the submission data to entity by: $form->bind($this->request->getPost(), $modelentity); Note: the name of radio element must be match with the name of the field in modelentity. In your case, the name of the radio element is "type" and you must sure "type" is the property of your model_entity