Skip to content

Instantly share code, notes, and snippets.

@vinacode
Created January 9, 2015 04:12
Show Gist options
  • Save vinacode/4f0a2dea6682e4c0f4a4 to your computer and use it in GitHub Desktop.
Save vinacode/4f0a2dea6682e4c0f4a4 to your computer and use it in GitHub Desktop.
CakePHP 3.0 Contact form
<?php
namespace App\Form;
use Cake\Form\Form;
use Cake\Form\Schema;
use Cake\Validation\Validator;
/**
* Description of ContactForm
*
* @author duanlq
*/
class ContactForm extends Form {
protected function _buildSchema(Schema $schema) {
return $schema->addField('name', 'string')
->addField('email', ['type' => 'string'])
->addField('body', ['type' => 'text']);
}
protected function _buildValidator(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) {
mail('[email protected]', 'test', 'ok');
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment