Created
July 10, 2013 18:33
-
-
Save alexander-torosh/5968873 to your computer and use it in GitHub Desktop.
Can't uncheck checkbox normaly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // My Entity | |
| class News extends \Phalcon\Mvc\Model | |
| { | |
| public $pub; // boolean field, Checkbox in Form | |
| public function getPub() | |
| { | |
| return $this->pub; | |
| } | |
| public function setPub($pub = null) | |
| { | |
| $this->pub = $pub; | |
| } | |
| } | |
| // Form | |
| class NewsForm extends \Phalcon\Forms\Form | |
| { | |
| public function initialize() | |
| { | |
| $pub = new \Phalcon\Forms\Element\Check("pub"); | |
| $pub->setLabel("Pub"); | |
| } | |
| } | |
| // Controller | |
| public function editAction($id) | |
| { | |
| $id = $this->filter->sanitize($id, "int"); | |
| $news = News::findFirst($id); | |
| $post = $_POST; | |
| if (!isset($post['pub'])) $post['pub'] = 0; // @todo I must use it, because News::setPub() not called when I try uncheck checkbox! | |
| $form = new NewsForm(); | |
| if ($this->request->isPost()) { | |
| $form->bind($post, $news); | |
| if ($form->isValid()) { | |
| $news->save(); | |
| $this->response->redirect('news/admin/edit/' . $id); | |
| } | |
| } else { | |
| $form->setEntity($news); | |
| } | |
| $this->view->setVar('form', $form); | |
| $this->view->setVar('news', $news); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment