Skip to content

Instantly share code, notes, and snippets.

@romaninsh

romaninsh/Model.md

Last active Oct 5, 2017
Embed
What would you like to do?
class User extends \atk4\data\Model
{
    function init() {
        parent::init();

        $this->addField('name');
        $this->addField('email');
    }
}
$form = $app->add(['Form', 'segment']);
$form->setModel(new User($db), ['email', 'password']);
$form->addField('is_accept_terms', null, ['type'=>'boolean']);
$form->submitButton->set('Register');
$form->onSubmit(function ($form) {
if (!$form->model['is_accept_terms']) {
return $form->error('is_accept_terms', 'Please accept terms');
}
$form->model->save();
return $form->success('Thank you');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.