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

Sunday, July 10, 2022

[FIXED] How to customize the display of "There is already an account with this" message in Twig

 July 10, 2022     customization, message, symfony-4.4, textfield, twig     No comments   

Issue

I'm trying to customize the display of this error message "There is already an account with this" in Twig.

This is the relevant code in the form class:

->add('cin', TextType::class, [
            'required' => true,
        ])

And here is the relvant HTML/Twig code:

<div class="form-outline">
   {{ form_row(registrationForm.cin ,{'label':false,'attr':{'placeholder':'Numéro carte d\'identité', 'name':'cin', 'class':'form-control', 'id':'cin', 'type':'number', 'minlength':'8', 'maxlength':'8', 'required data-error':'Veuillez saisir votre numéro de carte d\'identité', } } ) }}
   <span style="color: red">{{ form_errors(registrationForm.cin) }}</span>
</div>

This is what I get on my screen in case there is an error:

enter image description here

However, What I would like to get is only the red message (that is below the text field) customized to something like "Invalid card ID", for instance. So, what's wrong in my code? Any idea?


Solution

After some more research we identified that the error message can be changed in the @UniqueEntity validator in the user class.

Changing the current validator from

/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"cin"}, message="There is already an account with this cin")
*/

to

/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"cin"}, message="Invalid card id")
*/

results in the validation error message acutally being modified accordingly.



Answered By - daviid
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • 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