Hi,
I created a contact form with its own model. The model includes some
validation rules.
I'm calling validates() in the controller after setting up the model's
data. The problem is that validates() always returns true, even if I
don't write anything into the form.
Here's my code:
Controller:
<?php
class ContactController extends AppController {
var $name = 'Contact';
var $helpers = array('Html', 'Form');
function beforeFilter() {
parent::beforeFilter();
$this->Auth->autoRedirect = false;
if(isset($this->Auth)) {
$this->Auth->allow();
$this->Auth->authorize = "controller";
}
}
function index() {
if(!empty($this->data)) {
$this->Contact->set($this->data);
if($this->Contact->validates()) {
...
}
}
}
}
?>
Model:
<?php
class Contact extends AppModel {
var $useTable = false;
var $_schema = array(
'name' => array(
'type' => 'string'
),
'email' => array (
'type' => 'string'
),
'message' => array(
'type' => 'text'
),
'receiver' => array(
'type' => 'string'
)
);
var $validate = array(
'name' => array('rule'=>'notempty', 'message'=>'Bitte einen
Namen angeben'),
'receiver' => array('rule'=>'notempty', 'message'=>'Bitte
einen
Empfänger angeben'),
'email' => array('rule'=>'email', 'message'=>'Bitte eine
gültige
E-Mail angeben'),
'message' => array('rule'=>'notempty', 'message'=>'Bitte
eine
Nachricht angeben')
);
}
?>
View:
<?
echo $form->create('contact', array('url'=>array
('controller'=>'contact', 'action'=>'index')));
echo $form->input('receiver');
echo $form->input('name');
echo $form->input('email');
echo $form->input('message');
echo $form->end("Abschicken");
?>
Any ideas what's wrong? I'm really confused.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---