Hello!!! Create a form with two element (Text, Check). After submitting the form data, the check mark is not saved. With text elements are no problems, they retain the entered values
|
Oct '14 |
16 |
3396 |
3 |
Hello!!! Create a form with two element (Text, Check). After submitting the form data, the check mark is not saved. With text elements are no problems, they retain the entered values
We're aware of that, and that is happening because (contrary to the expected), Phalcon does not compare the value in the check with the one that comes up from $_POST, instead of that the value is ignored because of the one already defined in the check's parameters, hope to change this behavior in a further release
Yes, it's fixed, check in the online Vokuro: https://vokuro.phalcon.io/session/signup, if you accept/don't accept the terms and conditions the check value is kept between reloads
Hey @Phalcon,
that's good to hear, because it means I'm doing something wrong :).
In my form I have a checkbox like this:
$published = new Check('published', array(
'value' => '1'
));
$published->setLabel('Published?');
$this->add($published);
I initialize this form like every other:
public function initialize($entity)
{
$this->setEntity($entity);
When I create this form by passing an entity to it, for example $form = new MyForm(Entity::findFirst(1)); I get a form with the data from this entity pre-filled (title, text etc.), however my checkbox is never checked, no matter what value (1, '1', true) I make the entity pass along for it. Any ideas?
Thanks. It works. But I I was faced with a new problem. Details: https://gist.github.com/webtor/5968873
When checkbox is not checked, in $_POST this var isn't set. When I try save Entity, method set variable not called.
That would be the regular and expected behavior of any checkbox.
Try this out to confirm:
<?php var_dump($_POST); ?>
<form action="?" method="post">
<input type="checkbox" name="test" value="1" /> Check me out, I send "1" if checked and nothing if not checked.
<input type="submit" />
</form>
Use option fields to avoid that problem.
When we using Form with Entity
$form->bind($_POST, $entity);
Good framework must consider all elements in Form and all options in Entity. We don't must working with crutches and replace checkbox to options. According to this principle works ZendFramework, Symfony and others. I want that Phalcon was the best framework with useful and comfortable capabilities.