Created
July 23, 2010 15:22
-
-
Save meeech/487575 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
Hi. Trying to validate a model inside the controller. | |
Thing is, I am trying to submit a few at once. | |
I've made the forms fields like so: | |
ShareMail.0.name, | |
ShareMail.0.email, | |
ShareMail.1.name, | |
ShareMail.1.email, | |
but am having trouble validating them in the controller. | |
Trying to follow directions on | |
http://book.cakephp.org/view/410/Validating-Data-from-the-Controller | |
Cake 1.2 | |
Tried using $this->Model->validates() as well as saveAll with validate=>only, but neither works. | |
<?php | |
// From my controller | |
function _share_postcard() { | |
if(!empty($this->data)) { | |
$this->ShareMail = ClassRegistry::init('ShareMail'); | |
$this->ShareMail->set($this->data); | |
if($this->ShareMail->saveAll($this->data, array('validate'=>'only'))) { | |
$this->setFlashSuccess(__('external_postcard_thankyou', true)); | |
} | |
} | |
} | |
?> | |
<?php | |
/** | |
* ShareMail Class. For sending email using the share/postcard form. | |
*/ | |
class ShareMail extends AppModel { | |
public $useTable = false; | |
public $validate = array( | |
'name' => array('notempty'), | |
'email' => array( | |
'existence' => array( | |
'rule' => 'email', | |
'allowEmpty' => false | |
), | |
) | |
); | |
var $_schema = array( | |
'name' => array('type'=>'string', 'length'=>255), | |
'email' => array('type'=>'string', 'length'=>255), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment