Reputation: 3974
I am learning Cake now and am following IBM's tutorial. I have completed the Blog tutorial successfully from the cake site.
My problem is that the Register
view does not show up. Instead of showing the form, the register()
action is immediately performed and the condition checking whether the form's parameters are empty always fails so I always get to the failed to register user message.
The ctp file looks like this (it's not using the helpers):
<form action="/users/register" method="post">
<p>Please fill out the form below to register an account.</p>
<label>Username:</label><input name="username" size="40" />
<label>Password:</label><input type="password" name="password" size="40" />
<label>Email Address:</label><input name="email" size="40" maxlength="255" />
<label>First Name:</label><input name="first_name" size="40" />
<label>Last Name:</label><input name="last_name" size="40" />
<input type="submit" value="register" />
</form>
And the register()
action is:
function register() {
if (!empty($this->params['form']))
{
if ($this->User->save($this->params['form']))
{
$this->flash('Your registration infomration was accepted.', '/users/register');
}
}
else
{
$this->flash('There was a problem with your registration', '/users/register');
}
}
Upvotes: 0
Views: 54
Reputation: 1835
Try:
function register() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->flash('Your registration infomration was accepted.', '/users/register');
} else {
$this->flash('There was a problem with your registration', '/users/register');
}
}
}
The big difference being using $this->data
instead of $this->params[form]
and adding $this->User->create();
. Also the else statement should be with if(user is saved) flash saved else flash not saved.
Upvotes: 1