Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:12:15+00:00 2026-06-14T06:12:15+00:00

I create a form using the form component of Symfony 2. As the validation

  • 0

I create a form using the form component of Symfony 2.
As the validation errors are translated in different translation domains, I want to inject this information as an option (translation_domain) during creation of the form, but dont find the right (successful) spot where to set… Any hints?

I use a custom type for bundling my form informations.

My custom type class:

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\NotBlank;

class LoginType extends AbstractType
{

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $collectionConstraint = $collectionConstraint = new Collection(array(
            'password' => array(new NotBlank(array('message' => 'custom.error.blank'))),
            'username' => array(new NotBlank(array('message' => 'custom.error.blank')))
        ));

        $resolver->setDefaults(array(
            'constraints' => $collectionConstraint
        ));
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('username', 'text', array(
            'max_length'        => 250,
            'trim'              => true
        ));
        $builder->add('password', 'password', array(
            'max_length'        => 250,
            'trim'              => true
        ));
    }

    public function getName()
    {
        return 'login';
    }
}

relevant code snippets on form creation in controller:

$loginForm = $this->createForm(new LoginType(), $loginDefaultData);

$loginForm->bind($request);

[...]

return $this->render(
    'MyBundle:SubFolder:login.html.twig',
    array(
        'loginForm' => $loginForm->createView()
    )
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:12:17+00:00Added an answer on June 14, 2026 at 6:12 am

    After returning to the problem a while later, I found the reason: the dynamic translation_domain can be set within setDefaultOptions as followed.

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        // ...
    
        $resolver->setDefaults(array(
            'constraints'        => $collectionConstraint,
            'translation_domain' => 'customTranslationDomain'
        ));
    }
    

    However, in the used twig template, this translation_domain is used for labels and options, but the error messages are not served with this translation_domain. they are always translated with the same fixed set domain ‘validators’ in the default twig template at

    /Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

    It normally makes sense to bundle these messages in one domain, but not in my case, as the same constraint (and its error message) has to be translated in different ways depending on context and each context was organized in a isolated domain.

    My solution was to customize the form rendering as described in the Symfony2 documentation, redefine the form_errors fragment and use the dynamic translation_domain twig variable also for the error message output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying using a TAdoTable component, On form Create I call .Append() and in
I want to create a form using an unordered list ul must have only
I am new In ASP.NET, I want to create to Login Form using Membership
i want to create a dynamic generated form using javascript, everything works fine, until
I'm trying to create a form using Zend_Form (Zend_Framework component). The users should be
About to create a form using Zend Form, all the form elements should have
Code to create new form instance of a closed form using form name I
I am trying to create a form using only JavaScript. I mean create a
I am new to zend. I am trying to create login form using zend
I am trying to create a form in Sharepoint using C#. I don't know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.