Your $validate is wrong totally as you not specified validation rules.
Should be this:
var $validate = array(
'username' => array(
'required' => true,
'rule' => 'notEmpty',
'message' => 'Username is required'
),
'password' => array(
'required' => true,
'rule' => 'notEmpty',
'message' => 'Password is required'
)
);
On Jun 15, 8:19 pm, RhythmicDevil <[email protected]> wrote:
> Hi,
> having a little problem with validation. I am not using a DB. I have
> to auth against Web Services. I am currently just working on the login
> page trying to get messages to the view when validation fails.
>
> Here is the Model:
>
> class User extends AppModel
> {
> var $useDbConfig = 'soap';
> var $useTable = false;
>
> var $validate = array(
> 'username' => array(
>
> 'required' => true
>
> ,'allowEmpty' => false
>
> ,'message' => 'Username is required'
>
> )
> ,'password' => array(
>
> 'required' => true
>
> ,'allowEmpty' => false
>
> ,'message' => 'Password is required'
>
> )
> );
>
> }
>
> Here is the Controller:
>
> class UsersController extends AppController
> {
> public $layout = 'login';
> public $fields = array ('username', 'password');
>
> function index()
> {
>
> }
>
> function login()
> {
>
> // First set the data to the model
> $this->User->set( $this->data );
>
> // Check for validity
> if($this->User->validates())
> {
> print 'valid';
> }
> else
> {
> print 'invalid';
> }
> $this->render('index');
> }
>
> function logout()
> {
>
> }
>
> }
>
> So pretty straight forward stuff. However when I submit the form I get
> the following error from Cake whether there is data in the fields or
> not:
>
> Warning (2): preg_match() [function.preg-match]: Delimiter must not be
> alphanumeric or backslash [CORE\cake\libs\model\model.php, line 2431]
>
> Code | Context
>
> $this = User
> User::$useDbConfig = "soap"
> User::$useTable = false
> User::$validate = array
> User::$displayField = NULL
> User::$id = false
> User::$data = array
> User::$table = "users"
> User::$primaryKey = "id"
> User::$_schema = NULL
> User::$validationErrors = array
> User::$tablePrefix = NULL
> User::$name = "User"
> User::$alias = "User"
> User::$tableToModel = array
> User::$logTransactions = false
> User::$transactional = false
> User::$cacheQueries = false
> User::$belongsTo = array
> User::$hasOne = array
> User::$hasMany = array
> User::$hasAndBelongsToMany = array
> User::$actsAs = NULL
> User::$Behaviors = BehaviorCollection object
> User::$whitelist = array
> User::$cacheSources = true
> User::$findQueryType = NULL
> User::$recursive = 1
> User::$order = NULL
> User::$__exists = NULL
> User::$__associationKeys = array
> User::$__associations = array
> User::$__backAssociation = array
> User::$__insertID = NULL
> User::$__numRows = NULL
> User::$__affectedRows = NULL
> User::$_findMethods = array
> User::$_log = NULL
> $options = array()
> $data = array(
> "username" => "",
> "password" => ""
> )
> $methods = array(
> "__construct",
> "call__",
> "bind",
> "bindmodel",
> "unbindmodel",
> "__createlinks",
> "__constructlinkedmodel",
> "__generateassociation",
> "setsource",
> "set",
> "deconstruct",
> "schema",
> "getcolumntypes",
> "getcolumntype",
> "hasfield",
> "create",
> "read",
> "field",
> "savefield",
> "save",
> "__savemulti",
> "updatecountercache",
> "_prepareupdatefields",
> "saveall",
> "__save",
> "updateall",
> "remove",
> "del",
> "delete",
> "_deletedependent",
> "_deletelinks",
> "deleteall",
> "__collectforeignkeys",
> "exists",
> "hasany",
> "find",
> "_findfirst",
> "_findcount",
> "_findlist",
> "_findneighbors",
> "_findthreaded",
> "__filterresults",
> "resetassociations",
> "isunique",
> "query",
> "validates",
> "invalidfields",
> "invalidate",
> "isforeignkey",
> "getdisplayfield",
> "escapefield",
> "getid",
> "getlastinsertid",
> "getinsertid",
> "setinsertid",
> "getnumrows",
> "getaffectedrows",
> "setdatasource",
> "getdatasource",
> "getassociated",
> "joinmodel",
> "beforefind",
> "afterfind",
> "beforesave",
> "aftersave",
> "beforedelete",
> "afterdelete",
> "beforevalidate",
> "onerror",
> "_clearcache",
> "__sleep",
> "__wakeup",
> "findall",
> "findcount",
> "findallthreaded",
> "findneighbours",
> "overload",
> "__call",
> "object",
> "tostring",
> "requestaction",
> "dispatchmethod",
> "_stop",
> "log",
> "_set",
> "cakeerror",
> "_persist",
> "_savepersistent",
> "__openpersistent"
> )
> $behaviorMethods = array()
> $Validation = Validation
> Validation::$check = NULL
> Validation::$regex = NULL
> Validation::$__pattern = array
> Validation::$country = NULL
> Validation::$deep = NULL
> Validation::$type = NULL
> Validation::$errors = array
> Validation::$_log = NULL
> $_validate = array(
> "username" => array(
> "required" => true,
> "allowEmpty" => false,
> "message" => "Username is required"
> ),
> "password" => array(
> "required" => true,
> "allowEmpty" => false,
> "message" => "Password is required"
> )
> )
> $whitelist = array()
> $ruleSet = array(
> "required" => true,
> "allowEmpty" => false,
> "message" => "Username is required"
> )
> $fieldName = "username"
> $default = array(
> "allowEmpty" => null,
> "required" => null,
> "rule" => "blank",
> "last" => false,
> "on" => null
> )
> $validator = array(
> "allowEmpty" => null,
> "required" => null,
> "rule" => true,
> "last" => false,
> "on" => null
> )
> $index = "required"
> $message = "This field cannot be left blank"
> $required = false
> $rule = true
> $ruleParams = array(
> "steve"
> )
> $valid = true
>
> preg_match - [internal], line ??
> Model::invalidFields() - CORE\cake\libs\model\model.php, line 2431
> Model::validates() - CORE\cake\libs\model\model.php, line 2303
> UsersController::login() - APP\controllers\users_controller.php, line
> 20
> Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
> Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 227
> Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 194
> [main] - APP\webroot\index.php, line 88
>
> Warning (2): preg_match() [function.preg-match]: Empty regular
> expression [CORE\cake\libs\model\model.php, line 2431]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---