After doing some reading and looking at 1.2 validation, I thought I
had a pretty good understanding of the process.
However, let's say I wanted manually validate a bit of data coming
from a post using the standard model validation features. Seems like
it should be fairly straightforward, but I can't seem to get the
result I'm going for.
Since I'm not doing a "save", I'm just doing a findAll() on a Model,
but I want it to validate prior to doing the findAll().
For instance (highly simplified):
:::MODEL:::
-----------------------------------------------------------------
<?php
class RegTag extends AppModel
{
var $useTable = 'reg_tags';
var $validate = array(
'what' => 'alphaNumeric',
'where' => 'alphaNumeric'
);
}
?>
-----------------------------------------------------------------
:::CONTROLLER:::
-----------------------------------------------------------------
<?php
class IndexController extends AppController {
var $name = 'Index';
var $helpers = array('html', 'time', 'javascript', 'ajax');
var $uses = array('RegTag');
/** main action (starting point) **/
function search ()
{
/** we have a search **/
if ($this->RegTag->create($this->data) && $this->RegTag-
>validates()) {
//do something
} else {
//error
}
}
}
?>
-----------------------------------------------------------------
:::VIEW:::
-----------------------------------------------------------------
<?php echo $form->create('search', array('type' => 'post',
'action' => 'search', 'id' => 'request-form')); ?>
<?php echo $form->input('what', array('type' => 'text',
'label' => false)); ?>
<?php echo $form->error('what', 'Please enter what!'); ?>
<?php echo $form->input('where', array('type' => 'text',
'label' => false)); ?>
<?php echo $form->error('where', 'Please Enter Where!'); ?>
<?php echo $form->end('Search'); ?>
-----------------------------------------------------------------
Assuming that's the basics of the search, shouldn't validation be
working? As of right now, it doesn't. The [$this->RegTag-
>create($this->data) && $this->RegTag->validates()] check always
returns false, no matter what I enter into the form.
Any help would be greatly appreciated!
Cake Fan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---