Symfony form values missing

此生再无相见时 提交于 2019-12-12 13:58:02

问题


I was writing a simple login form, everything works fine (validation etc.) but I can't get the values, there's my code:

public function executeIndex(sfWebRequest $request)
  {
      $this->getUser()->clearCredentials();
      $this->getUser()->setAuthenticated(false);

      $this->form = new LoginForm();

      if ($request->isMethod('post') && $request->hasParameter('login')) {
          $this->form->bind($request->getParameter('login'));

          if ($this->form->isValid()) {

              $this->getUser()->setAuthenticated(true);
              $this->getUser()->addCredential('user');
              $this->login = $this->form->getValue('login');
          }
      }
  }

$this->login is NULL. Now I checked almost everything, the form is valid, isBound() is true, count() returns 3, I can see the values in my request:

parameterHolder:
  action: index
  login: { login: foo, password: foo, _csrf_token: 53ebddee1883d7e3d6575d6fb1707a15 }
  module: login

BUT getValues() returns NULL, getValue('login') etc. returns NULL as well. How can it be?

And no, I don't want to use sfGuard-Plugins ;)


回答1:


What about trying something like this

$form['value_name']->getValue()

Is it still NULL?

Also is it possible that you created a custom post validator?




回答2:


Callback validation must return values back to caller:

return $values;


来源:https://stackoverflow.com/questions/2662708/symfony-form-values-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!