Open
Description
Describe the bug
Based on how bind works and checks for elements, radios do not work (https://github.com/phalcon/cphalcon/blob/v4.1.3/phalcon/Forms/Form.zep#L160)
This bug could affect multiple things like Tag::setDefault() for example.
To Reproduce
The problem with radios is, that they need to be added with a different name, else they overwrite themself.
$entity = new \Vokuro\Models\Users();
$form = new \Vokuro\Forms\UsersForm($entity);
$form->remove('banned');
$form->add(new Radio('r0', ['name' => 'banned', 'value' => 'no']);
$form->add(new Radio('r1', ['name' => 'banned', 'value' => 'yes']);
// Simulate POST data
$form->bind(['banned' => 'yes'], $entity);
echo $entity->banned; // displays null or default value
Expected behavior
The form should bind the value to the correct element.
Workaround
The current workaround for this problem is the following. Maybe the workaround should be done automatically and not rendered ever.
$entity = new \Vokuro\Models\Users();
$form = new \Vokuro\Forms\UsersForm($entity);
$form->remove('banned');
$form->add(new Radio('r0', ['name' => 'banned', 'value' => 'no']);
$form->add(new Radio('r1', ['name' => 'banned', 'value' => 'yes']);
// Workaround (can apply filters here etc. (should not be rendered)
$form->add(new Hidden('banned'));
// Simulate POST data
$form->bind(['banned' => 'yes'], $entity);
echo $entity->banned; // displays yes now
Details
- Phalcon version: 4.1.3
- PHP Version: 7.4
- Operating System: debian
- Installation type: Compiling from source
- Zephir version (if any): none
- Server: Nginx
- Other related info (Database, table schema): none
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Backlog