244863 Posted March 20, 2013 Share Posted March 20, 2013 VIEW: <div class="column span-24"> <div class="box"> <?php echo $this->html->tag('h2', $title_for_layout); echo $this->form->create('Job', array('action' => 'add')); echo $this->form->inputs(array( 'description' => array( 'class' => 'span-22' ) )); echo $this->element('standard-form-buttons'); ?> </div> </div> CONTROLLER: public function add() { $this->set('title_for_layout', __('Create new Job', true)); if ($this->request->is('post')) { $this->request->data['Job']['created_by'] = $this->Auth->user('id'); unset($this->request->data['Job']['asset_category_id']); $this->Job->set($this->request->data); if ($this->Job->validates()) { $this->Job->create(); if ($this->Job->save($this->request->data, array($params = array('validate' => 'first')))) { $this->Session->setFlash('The job has been saved'); $this->redirect(array('controller' => 'jobs', 'action' => 'index')); } else { $this->Session->setFlash('The job could not be saved. Please, try again.'); } }else{ $errors = $this->ModelName->invalidFields(); } } } MODEL: <?php class Job extends AppModel { public $validate = array( 'Job.description' => array( 'notEmpty' => array( 'rule' => 'notEmpty', 'message' => 'The descripton must be completed.' ) ) ); } ?> IT won't show the validation errors on the form when I hit save??? any ideas what I am doing wrong? Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 20, 2013 Share Posted March 20, 2013 In your model, try changing 'Job.description' => array( to 'description' => array( Quote Link to comment Share on other sites More sharing options...
244863 Posted March 20, 2013 Author Share Posted March 20, 2013 Tried that both ways. It just says the standard (Please fill out this field) from the DB as it is a required field and not the validation I stipulated below for minLength??? public $validate = array( 'description' => array( 'rule' => array('minLength', , 'message' => 'The descripton must be completed.' ) ); Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 20, 2013 Share Posted March 20, 2013 (edited) That's a different problem than the first post, and different code. It helps if you actually explain the problem. It looks fine, according to the manual. http://book.cakephp.org/2.0/en/models/data-validation.html What happens when you enter a string that is less than 8 long? Don't forget to read the section on multiple rules. http://book.cakephp.org/2.0/en/models/data-validation.html#multiple-rules-per-field Edited March 20, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
244863 Posted March 20, 2013 Author Share Posted March 20, 2013 I was using $this->Model->Validates() and $this->Model->Save() which validates as well. When I removed the Validates() and left just the save() everything works. Serves me right for trying to validate twice. thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.