Skip to content

Instantly share code, notes, and snippets.

@meeech
Created July 23, 2010 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meeech/487575 to your computer and use it in GitHub Desktop.
Save meeech/487575 to your computer and use it in GitHub Desktop.
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