Created
January 9, 2015 04:12
-
-
Save vinacode/4f0a2dea6682e4c0f4a4 to your computer and use it in GitHub Desktop.
CakePHP 3.0 Contact form
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
<?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