PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 10, 2022

[FIXED] How to get only text instead of list item from form_errors

 July 10, 2022     forms, message, symfony-4.4, text, twig     No comments   

Issue

I'm trying to display an error message for a repeated password field in Symfony 4.4.

Here is the relevant code in the form class file:

->add('password', RepeatedType::class, array(
            'required' => true,
            'invalid_message' => 'Le mot de passe et sa confirmation ne sont pas identiques',
            'type' => PasswordType::class,
            'first_options' => array('label' => false,'error_bubbling' => true),
            'second_options' => array('label' => false),
        ))

And here is my relevant twig/HTML code:

<div class="col-md-4 mb-4">
                                    <div class="form-outline">
                                        {{ form_row(registrationForm.password.first ,{'label':false,'attr':{'placeholder':'Mot de passe', 'name':'password1', 'class':'form-control', 'id':'password1'} } ) }}
                                        <span style="color: red">{{ form_errors(registrationForm.password|first) }}</span>
                                    </div>
                                </div>

Actually, if I change form_errors(registrationForm.password|first) to form_errors(registrationForm.password), I get this:

enter image description here

However, that is not the wanted result since I need to display only a simple text, and I really wonder why form_errors(registrationForm.password|first) didn't work for me. Any idea?


Solution

I've fixed it! I've actually followed a different approach. In my HTML\Twig code, I've changed this line <span style="color: red">{{ form_errors(registrationForm.password|first) }}</span> like so:

<span class="Errormessage" style="color: red;text-align: right">{{ form_errors(registrationForm.password) }}</span>

Then, I added the code below in my CSS code:

.Errormessage li {
    list-style-type: none !important;
}


Answered By - Nadim
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing