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 7445621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:53:08+00:00 2026-05-29T11:53:08+00:00

I created a FormType for a registration form. The validation work like it should.

  • 0

I created a FormType for a registration form. The validation work like it should. Strange thing is:
The errors get printed right away. When displayed (on load of the page), the form tells me right away that some fields are not valid, although I haven’t started to fill in the fields at that point.

my formtype class:

<?php
namespace MyBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\MaxLength;
use Symfony\Component\Validator\Constraints\MinLength;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use MyBundle\Validation\Constraint\Unique;
use MyBundle\Validation\Constraint\InvitationCode;
use MyBundle\Validation\Constraint\Username;

class RegistrationFormType extends AbstractType
{
    /**
     *
     * @var FormBuilder
     */
    private $builder;

    public function buildForm(FormBuilder $builder, array $options)
    {
        $this->builder = $builder;
        $this->builder
            ->add('code','text', array(
                'label' => 'Einladungscode'
            ))->add('username','text',array(
                'label' => 'Benutzername',
            ))
            ->add('email', 'email',array(
                'label' => 'E-Mail'
            ))
            ->add('plainPassword', 'repeated', array('type' => 'password',
                'first_name'=>'Passwort',
                'second_name'=> 'Passwort wiederholen',
                )
            );
    }

    public function showRegistrationFields(){


    }
    public function getDefaultOptions(array $options)
    {
        $collectionConstraint = new Collection(array(
            'email' => array(
                    new NotBlank(),
                    new Unique(array(
                        'entityName' => 'AjadoEventHubBundle:User',
                        'propertyName' => 'email')),
                    new Email(array(
                            'message' => 'Ungültige E-Mail Adresse',
                        )),

                ),
            'username' => array(
                    new NotBlank(),
                    new Unique(array(
                        'entityName' => 'AjadoEventHubBundle:User',
                        'propertyName' => 'username')),
                    new Username(),
                    new MinLength(array('limit' => 5)),
                    new MaxLength(array('limit' => 40)),
                ),
            'code' => array(
                    new MaxLength(array('limit'=>200)),
                    new InvitationCode(),
                ),
            'plainPassword' => array(
                    new MaxLength(array('limit'=>20)),
                    new MinLength(array('limit' => 5))
                ),
        ));

        return array(
            'csrf_protection' => false,
            'validation_constraint' => $collectionConstraint,
        );
    }

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

}
  • 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-05-29T11:53:19+00:00Added an answer on May 29, 2026 at 11:53 am

    I changed

    $form->bindRequest($this->getRequest());
    if ($this->getRequest()->getMethod() == 'POST' && $form->isValid()) {
    

    to

    if ($this->getRequest()->getMethod() == 'POST') {
                $form->bindRequest($this->getRequest());
                if($form->isValid()){
    

    Thanks @meze for the hint!

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

Sidebar

Related Questions

Created a custom validation attribute and I would like to get it to work
Created a views.py method to get the data posted from an html form. As
I'm trying to override FOSUserBundle form Edit profile ; I have created the class
I am using embedded forms to be able to make a registration form, which
I've got a problem when I want to override the FOSUserBundle registration Form. The
Created a group of related providers using the provider pattern. Now would like to
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created a single page (with code behind .vb) and created Public intFileID As

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.