Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created February 25, 2012 14:42
Show Gist options
  • Save icambridge/1908807 to your computer and use it in GitHub Desktop.
Save icambridge/1908807 to your computer and use it in GitHub Desktop.
CakePHP model validation match
<?php
class Test extends AppModel {
public $name = 'Test';
public $validate = array(
'field' => array(
array(
'rule' => array('match','field_confirm.'),
'message' => 'The field must match.'
)
),
);
public function match($data, $otherField) {
$fieldValue = current($data);
$otherFieldValue = $this->data[$this->name][$otherField];
return ($fieldValue === $otherFieldValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment