D
D
Denis2012-07-10 11:42:30
symfony
Denis, 2012-07-10 11:42:30

How to set form field name manually?

There is a form class:

class LoginForm extends AbstractType<br>
{<br>
    public function buildForm(FormBuilder $builder, array $options)<br>
    {<br>
        $builder->add('username','text');<br>
        $builder->add('password','password');<br>
    }<br><br>
    public function getName()<br>
    {<br>
        return 'login';<br>
    }<br>
}<br>

Code generated:
<form action="/app_dev.php/login_check" method="post"><br>
    <div id="login"><br>
    <input type="hidden" id="login__token" name="login[_token]" value="b7521243e04f79fb55c77c6ea8dc782578beab99" /><br>
    <div><br>
      <label for="login_username" class=" required">Username</label><br>
      <input type="text" id="login_username" name="login[username]" required="required" /><br>
    </div><br>
    <div><br>
      <label for="login_password" class=" required">Password</label><br>
      <input type="password" id="login_password" name="login[password]" required="required" /><br>
    </div><br>
  </div><br>
    <input type="submit" name="login" /><br>
</form>

For authorization, Symfony requires field names: username and password.
If set in config like this:
form_login:<br>
        check_path: /login_check<br>
        login_path: /login<br>
        username_parameter: login[username]<br>
        password_parameter: login[password]

That still doesn't work.
How to set the fields to their names or how to tell the authorization to use such names?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Slinko, 2012-07-10
@newpdv

The authorization form is written manually, because. there is no sense from the class - form_login makes a redirect.

F
freeek, 2012-07-10
@freeek

Doki :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question