1

I'm writing my first CakePHP application and am just writing the second part of a password reset form where a user has received an email containing a link to the site and when they click it they're asked to enter and confirm a new password.

The url of the page is like this:

/users/reset_password_confirm/23f9a5d7d1a2c952c01afacbefaba41a26062b17

The view is like:

<?php echo $form->create('User', array('action' => 'reset_password_confirm')); ?>
<?php 
    echo $form->input('password', array('label' => 'Password'));
    echo $form->input('confirm_password', array('type' => 'password', 'label' => 'Confirm password'));
    echo $form->hidden('static_hash');
?>
<?php echo $form->end('Reset password'); ?>

However this produces a form like:

<form id="UserResetPasswordConfirmForm" method="post" action="/users/reset_password_confirm/8">

The problem is the user id (8 in this case) is being added to the form action. It's not really a problem here, but when I want to pass through the hash to my controller:

function reset_password_confirm($static_hash=null) {
    // function body
}

$static_hash is now populated with 8 rather than the hash from the URL.

I know I could sort this out by creating the form tag myself rather than using $form->create but is there a more cakey way of doing this?

2 Answers 2

1
$form->create('User', array('action' => '…', 'id' => false));

Just explicitly set params you don't want passed to null or false. This is unfortunately a case where Cake tries to be a little too intelligent for its own good. ;o)

You could probably also do something like this to POST to the same URL again:

$form->create('User', $this->here);
Sign up to request clarification or add additional context in comments.

Comments

0

How about passing it as a parameter instead of form data :

<?php
echo $form->create('User', array('action' => 'reset_password_confirm', $static_hash));
    echo $form->input('password', array('label' => 'Password'));
    echo $form->input('confirm_password', array('type' => 'password', 'label' => 'Confirm password'));
echo $form->end('Reset password');
?>

and in the controller :

function reset_password_confirm($static_hash = null) {

// Check if form is submitted
if (!empty($this->data)) {
  // if it submitted then do your logic
} else {
  $this->set('static_hash', $static_hash); // Else, pass the hash to the view, so it can be passed again when form is submitted
}

}

Hope this help :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.