Symfony - 我不能用树枝定制我的表格

I would like to create a login form in twig (login + password) and which is customized. The form should search the Users table and the LDAP directory if the information entered exists.

Moreover, when I validate the form, I do not want the login and the password to be found in the URL.

At validation, if the user exists, he is redirected to a page, otherwise he will remain on the login page.

I managed to make a form, customized but that returns the login and password in the URL.

It looks like this:

enter image description here

And this is the code in twig :

{% extends 'base.html.twig' %}
{% block stylesheets %}
<link href="//" rel="stylesheet" id="bootstrap-css">
<script src="//"></script>
<script src="//"></script>rel="stylesheet"> 

{% endblock %}
{% block body %}

<form class="navbar-form navbar-center">
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
        <input id="text" type="text" class="form-control" name="login" value="" placeholder="Login">                                        
    <div class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
        <input id="password" type="password" class="form-control" name="password" value="" placeholder="Mot de passe">                                        
    <button type="submit" class="btn btn-primary">Valider</button>
    Pas de compte académique ? <a href="{{path('paquets_index')}}">Demande de création de compte</a>

{% endblock %}

Now my goal is to make sure that there is no login and password that are found in the URL to validation. It will just be a check and in function, it will show yes or no the next page. And I can not do it.

Moreover, from a functional point of view, is it useful to go through a formType builder from my Users entity? Or can I just be content with this kind of form, which would send back to the controller the information entered, to do the verification?

When in doubt, here is my form builder


namespace Site\PagesBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class ConnexionType extends AbstractType
     * {@inheritdoc}
    public function buildForm(FormBuilderInterface $builder, array $options)
        ->add('identifiant', TextType::class)
        ->add('password', PasswordType::class,array(
            'attr' => array(
                'placeholder'=> 'Mot de passe',
                'label' =>'Mot de passe',
     * {@inheritdoc}
    public function configureOptions(OptionsResolver $resolver)
            'data_class' => 'Site\PagesBundle\Entity\User'

     * {@inheritdoc}
    public function getBlockPrefix()
        return 'site_pagesbundle_user';


Thanks for your help !


I'm not quite sure, how bend on reinventing the wheel you are. But symfony has a lot of stuff prepared, since this is not that uncommon of a use case.

I like the 3.4 tutorial on building a login:

(at the side, there is the possibility to switch to 4.3 or whatever, however, the 3.4 tutorial should still work, even in 4.x)

you don't particularly need your own FormType to do the login, since the Security components already handle form submissions. Also have a look at csrf protection ;o)



我不太确定,重新发明轮子是多么弯曲。 但是symfony已经准备好了很多东西,因为用例并不常见。</ p>

我喜欢3.4关于构建登录的教程: </ p>

(在旁边,有可能切换到4.3或者其他什么,但3.4教程应该仍然可以工作,即使在4.x中)</ p>

你没有特别的 需要您自己的FormType才能进行登录,因为安全组件已经处理了表单提交。 另请参阅csrf保护; o)</ p>
</ div>

dongxuanchao1425 好的谢谢 ! :)
8 个月之前 回复
我在西湖1 我相信你可以结合它,我很确定,谷歌搜索将帮助你找到(你不会成为第一个挑战; o)
8 个月之前 回复
dqys98341 谢谢 ! 所以这将检查LDAP,但这是否意味着我必须为LDAP创建一个登录表单,为DB用户创建一个登录表单? 或者我可以两者结合?
8 个月之前 回复
8 个月之前 回复
douquejituan938904 你必须添加一个我怀疑的新UserProvider。
8 个月之前 回复
douxunnian0423 谢谢您的回答 ! 我刚看完这篇文章。 如果输入的数据存在,它会在Users表中查找,并自动重定向吗? 但是,如果此实用程序允许同时检查Users表和LDAP目录,则不会提及,是这种情况吗?
8 个月之前 回复

Currently you are not using your form generated by ConnexionType if you want to use it in your Twig file you can display it like that {{form(form) }} if you send it through your controller.

You have all the necessary information here

Then to not pass the login and password in the url use the POST method

Otherwise I recommend the security bundle Bundle Security to get a secure form

I hope I helped you.



目前您没有使用ConnexionType生成的表单,如果要在Twig文件中使用它,可以像 {{form(form)}} </ code>如果您通过控制器发送它。 </ p>

您在此处拥有所有必要信息 </ p>

然后不使用POST方法传递URL中的登录名和密码</ p>

否则我建议使用安全捆绑包捆绑安全以获得安全的表格</ p>

我希望我帮助过你。< / p>
</ div>

doupo2241 谢谢你的回答,我终于设法编辑了表格:)
8 个月之前 回复
8 个月之前 回复
dpi9530 您好,是的,我的目标正是使用formType,同时保持与我在第一张照片中发布的完全相同的渲染(设计)。 因为使用了formType,我无法在正确插入glyphicons的情况下获得Bootstrap 3渲染。
8 个月之前 回复
Csdn user default icon