cakephp/form

Name: form

Owner: CakePHP

Description: [READ-ONLY] - Form abstraction used to create forms not tied to ORM backed models, or to other permanent datastores.

Created: 2016-12-21 01:32:26.0

Updated: 2018-04-28 02:11:00.0

Pushed: 2018-05-21 01:41:09.0

Homepage: null

Size: 31

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Total Downloads License

CakePHP Form Library

Form abstraction used to create forms not tied to ORM backed models, or to other permanent datastores. Ideal for implementing forms on top of API services, or contact forms.

Usage
Cake\Form\Form;
Cake\Form\Schema;
Cake\Validation\Validator;

s ContactForm extends Form


protected function _buildSchema(Schema $schema)
{
    return $schema->addField('name', 'string')
        ->addField('email', ['type' => 'string'])
        ->addField('body', ['type' => 'text']);
}

public function validationDefault(Validator $validator)
{
    return $validator->add('name', 'length', [
            'rule' => ['minLength', 10],
            'message' => 'A name is required'
        ])->add('email', 'format', [
            'rule' => 'email',
            'message' => 'A valid email address is required',
        ]);
}

protected function _execute(array $data)
{
    // Send an email.
    return true;
}

In the above example we see the 3 hook methods that forms provide:

You can always define additional public methods as you need as well.

tact = new ContactForm();
cess = $contact->execute($data);
ors = $contact->errors();
Documentation

Please make sure you check the official documentation


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.