Created
January 9, 2015 03:16
-
-
Save markstory/2da2042a5e487ee110c1 to your computer and use it in GitHub Desktop.
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
<h1>Best contact form evar</h1> | |
<?php | |
echo $this->Form->create($form); | |
echo $this->Form->input('name'); | |
echo $this->Form->input('email'); | |
debug($this->Form->isFieldError('email')); | |
debug($this->Form->error('email')); | |
echo $this->Form->input('text'); | |
echo $this->Form->button('submit'); | |
echo $this->Form->end(); |
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\Controller; | |
use Cake\Form\Form; | |
use App\Controller\AppController; | |
class UsersController extends AppController | |
{ | |
public function contact() | |
{ | |
$form = new Form; | |
$form->schema() | |
->addField('name', 'string') | |
->addField('email', 'string') | |
->addField('text', 'text'); | |
$form->validator() | |
->requirePresence('name') | |
->add('name', 'len', ['rule' => ['minLength', 10]]) | |
->add('email', 'format', ['rule' => 'email']); | |
if ($this->request->is('post')) { | |
$valid = $form->validate($this->request->data); | |
if ($valid) { | |
$this->Flash->success('nice work!'); | |
} else { | |
$this->Flash->error('nope'); | |
} | |
} | |
$this->set(compact('form')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment