I have only recently started using CakePHP and have been unable to get validation to work in a contact app that I have created for the sole purpose of testing forms. Once I setup the $validate
array in the modal, the asterisks showed up on the form, however, I still am not getting the validation messages when I submit the form. Here is my code:
/app/View/Contacts/index.ctp
<h1>Contact Form</h1>
<?php
echo $this->Form->create('Contact');
echo $this->Form->input('name');
echo $this->Form->input('age');
echo $this->Form->end('Submit This Form!!!');
?>
/app/Controller/ContactsController.php
<?php
class ContactsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
}
}
?>
/app/Model/Contact.php
<?php
class Contact extends AppModel {
var $useTable = false;
public $validate = array(
'name' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
),
'age' => array(
'rule' => 'notEmpty',
'message' => 'Cannot leave this field blank.'
)
);
}
?>