0

I have a form field created using form builder. It looks like this:

    $builder
        ->add('firstName', null, array('required' => true, 'label' => 'First Name'))

Here is the full twig code for the form. I can't get the error message to display on fields when they blank on most of the fields. Email and password works fine but the other fields display no error message.

<div class="row">
    <div class="col-md-12">
        <div class="text-center">
            <h1>Create an Account</h1>
        </div>
        <div class="col-md-12">
            <div class="clear"></div>
        </div>
        <form id="loginForm" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
            {# {{ form_widget(form) }} #}
            {{ form_errors(form) }}

            <div class="col-md-3">
                <fieldset>
                    <legend>Email</legend>
                        {{ form_row(form.email.children['first'], { 'label': 'Email Address', 'attr' : { 'class' : 'form-control' } }) }}
                        {{ form_row(form.email.children['second'], { 'label': 'Verify Email', 'attr' : { 'class' : 'form-control' } }) }}
                        {{ form_errors(form.email) }}
                        {{ form_errors(form.phone) }}
                        <div class="clear-small"></div>
                        <div class="clear-small"></div>
                         <legend>Password</legend>
                        {{ form_row(form.plainPassword.children['first'], { 'label': 'Choose a Password', 'attr' : { 'class' : 'form-control' } }) }}
                        {{ form_row(form.plainPassword.children['second'], { 'label': 'Verify Password', 'attr' : { 'class' : 'form-control' } }) }}
                        {{ form_errors(form.plainPassword) }}
                </fieldset>
                <div class="clear"></div>
            </div>
            <div class="col-md-3">
                <fieldset>
                    <legend>Contact Information</legend>
                    {{ form_errors(form.firstName) }}
                    {{ form_row(form.firstName, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.lastName, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.company, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.phone, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.fax, {'attr' : { 'class' : 'form-control' } }) }}
                </fieldset>
            </div>
            <div class="col-md-3">
                <fieldset>
                    <legend>Company Information</legend>                   
                    {{ form_row(form.company, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.address, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.address2, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.zip, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.city, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.state, {'attr' : { 'class' : 'form-control' } }) }}
                    {{ form_row(form.country, {'attr' : { 'class' : 'form-control' } }) }}

                </fieldset>
            </div>
            <div class="col-md-3">
                <legend>Shipping Information</legend>      
                {{ form_row(form.ship_company, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_contact, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_address, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_address2, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_zip, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_city, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_state, {'attr' : { 'class' : 'form-control' } }) }}
                {{ form_row(form.ship_country, {'attr' : { 'class' : 'form-control' } }) }}             
                {{ form_row(form.ship_phone, {'attr' : { 'class' : 'form-control' } }) }}             
            </div>

            <div class="clear"></div>

            <div>
                {{ form_widget(form._token) }}
                <input class="dark-blue-bg white-text btn" type="submit" id="_submit" name="_submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}"/>
            </div>

        </form>
        <div class="clear"></div>
    </div>
</div>

When the user hits register without filling out first name they get no error text. How would I go about fixing that?

Thanks!

6
  • Have you tried $builder->add('firstName', TextType::class, ['required' => true] and remove , 'required' : 'required' in twig? Commented Sep 13, 2019 at 17:16
  • Yeah, still doesn't show error messages. Commented Sep 13, 2019 at 17:26
  • please post twig file Commented Sep 13, 2019 at 17:28
  • I edited the post. Commented Sep 13, 2019 at 17:33
  • Have you tried form_start - form_end ? {{ form_start(form, {id: "loginForm", 'method': 'POST', action: path('fos_user_registration_register'), class:"fos_user_registration_register" }) }} removing ` <form id="loginForm" ...` Commented Sep 13, 2019 at 18:11

1 Answer 1

0

Try using form_start

{{ form_start(form, {id: "loginForm", 'method': 'POST', action: path('fos_user_registration_register'), class:"fos_user_registration_register" }) }}

and remove

<form id="loginForm" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">

end close with form_end

Sign up to request clarification or add additional context in comments.

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.