I have started to look into CakePHP to increase my productivity. The problem is that I have run into a small problem, which has kept me occupied in more than one hour - when the form is submitted it is not validated.
Even though I intentionally leave both fields blank it still saves and gives the OK-message.
Hope somebody can help me get going again. If somebody knows an active CakePHP-forum i'd appreciate a link.
goods_controller.php
<?php
class GoodsController extends AppController {
var $name = 'Goods';
function index() {
$this->set('goods',$this->Good->find('all'));
}
function view($id = NULL) {
//list of fields+id, null meaning take all
$this->set('good',$this->Good->read(NULL, $id));
}
function add() {
//Is it not empty? Then lets go on and save the data
if(!empty($this->data)) {
$this->Good->Create();
if($this->Good->save($this->data)){
$this->Session->setFlash('Varen blev gemt succesfuldt');
//$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash('Varen kunne desværre ikke gemmes, prøv venligst igen!');
}
}
}
}
?>
add.ctp
<h1>Add Post</h1>
<?php
echo $form->create('Good', array('action'=>'add'));
echo $form->input('headline_dk');
echo $form->error('headline_dk');
echo $form->input('text_dk');
echo $form->error('text_dk');
echo $form->end('Indsæt vare');
?>
goods.php
class Good extends AppModel {
var $name = 'Good';
var $validate = array(
'headline_dk' => array(
'rule' => 'notEmpty',
'message' => 'Angiv venligst en titel'
),
'headline_dk' => array(
'rule' => array('between', 5, 255),
'message' => 'Titlen skal være mellem fem og 255 tegn'
)
'text_dk' => array(
'required' => true,
'message' => 'Angiv venligst en beskrivelse af varen'
)
};