Reputation: 15
Im new to cakePHP and tried to create a simple user registration. Now I'm stuck since two days in the validation of the form. The validation function returns always true and so the form is always saved to the database, even if it is empty.
So here are the model, the controller and the view. Maybe you can see what I did wrong here?
/app/Model/MemberModel.php
<?php
class Member extends AppModel {
var $validate = array(
"username" => array(
"rule" => "alphaNumeric",
"allowEmpty" => false
)
);
}
?>
/app/Controller/MemberController.php
<?php
class MemberController extends AppController {
var $components = array("Security");
var $helpers = array("Html", "Form");
public function index() {
}
public function register() {
if($this->request->is("post")) {
Security::setHash("blowfish");
$this->Member->set($this->request->data);
debug($this->Member->validates());
if($this->Member->save(array("password" => Security::hash($this->request->data["Member"]["password"])))) {
$this->Session->setFlash(__("Saved."));
} else {
$this->Session->setFlash(__("Error: ").$this->validationErrors);
}
}
}
}
?>
/app/View/Member/register.ctp
<?php
echo $this->Form->create("Member");
echo $this->Form->input("username");
echo $this->Form->input("password");
echo $this->Form->end("Register");
?>
Upvotes: 1
Views: 576
Reputation: 3078
Oh, I just realized your problem.
/app/Model/MemberModel.php
should be
/app/Model/Member.php
The controller will look for Member.php
, and if it can't find it, it will try the default $validate
behavior in AppModel
Upvotes: 2