3

EDIT: This question is for old version of phalcon. Phalcon now has 3.1 version, on which this issue seems to be fixed.

I have following controller action to sign user in.

public function signinAction()
{
    $form = new SigninForm;
    if ($this->security->checkToken())
    {
        try
        {
            $this->auth->signin($form);
        } catch (Exception $e)
        {
            $this->flash->error($e->getMessage());
        }
    }

    $form->clear();
    $form->get('password')->clear();
    \Phalcon\Tag::resetInput();
    $this->view->form = $form;
}

The above clear methods do not work and I get password field repopulated with user input.

EDIT: I am using Phalcon 2.0.10

traditional
  • 942
  • 10
  • 19

4 Answers4

1

I had the same problem just yesterday. Surprisingly in my case $form = new RegistrationFrom($user); did not help.

Turns out though if you do $user->setPassword(''); (assuming, that you have binded an entity to the form) it will clear the value, but if you set it to null it won't clear it, instead it will display the value initially binded to the form.

Terax
  • 130
  • 5
1

As of documentation says:

public clear () inherited from Phalcon\Forms\Element Clears every element in the form to its default value

I assume you have not declared default value of a field.

Please, do define a default value for this form element, eg.:

use \Phalcon\Forms\Element\Password;

class SigninForm extends ... {

    // ...

    $passwordField = new Password('password');
    $passwordField->setDefault('');

    // ...

    $this->add($passwordField);

After defining proper default value of a field, calling clear() method should start to work as expected.

yergo
  • 4,761
  • 2
  • 19
  • 41
1
$form->getElements()['password']->setAttribute('values' , '' );
0

Fixed in the 3.0.x branch.

git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build

Refs:

serghei
  • 3,069
  • 2
  • 30
  • 48