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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:57:46+00:00 2026-06-02T18:57:46+00:00

This is how my code snippet looks like. // — this is the code

  • 0

This is how my code snippet looks like.

// — this is the code in my controller —-

$registrationForm = $this->createFormBuilder()
                ->add('email')
                ->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'Passwords do not match'))
                ->getForm();

        return $this->render('AcmeHelloBundle:Default:index.html.twig', array('form' => $registrationForm->createView()));

// --- This is the twig file code----

<form action="#" method="post" {{ form_enctype(form) }}>
    {{ form_errors(form) }}
    {{ form_row( form.email, { 'label': 'E-Mail:' } ) }}
    {{ form_errors( form.password ) }}
    {{ form_row( form.password.first, { 'label': 'Your password:' } ) }}     
    {{ form_row( form.password.second, { 'label': 'Repeat Password:' } ) }}     
    {{ form_rest( form ) }}
    <input type="submit" value="Register" />
</form>

Can any one suggest why it is not working using form builder?

  • 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-02T18:57:47+00:00Added an answer on June 2, 2026 at 6:57 pm

    In Symfony 2, validation is handled by domain object. So you have to pass an Entity (domain object) to your form.

    Code in controller :

    public function testAction()
    {
        $registration = new \Acme\DemoBundle\Entity\Registration();
        $registrationForm = $this->createFormBuilder($registration)
                ->add('email')
                ->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'Passwords do not match'))
                ->getForm();
    
        $request = $this->get('request');
        if ('POST' == $request->getMethod()) {
            $registrationForm->bindRequest($request);
            if ($registrationForm->isValid()) {
                return new RedirectResponse($this->generateUrl('registration_thanks'));
            }
        }
    
        return $this->render('AcmeDemoBundle:Demo:test.html.twig', array('form' => $registrationForm->createView()));
    }
    

    1) The form builder will map the form fields with the properties of your entity, and hydrate your form field values with your entity property values.

    $registrationForm = $this->createFormBuilder($registration)...
    

    2) The bind will hydrate your form fields values with all the data posted

    $registrationForm->bindRequest($request);
    

    3 ) To launch validation

    $registrationForm->isValid()
    

    4) if the data posted are valid, you have to redirect to an action to inform user that everything is OK, to avoid displaying an alert message from your broswer who ask if your are sure to repost data.

    return new RedirectResponse($this->generateUrl('registration_thanks'));
    

    Entity code :

    <?php
    
    namespace Acme\DemoBundle\Entity;
    
    class Registration
    {
        private $email;
    
        private $password;
    
        public function getEmail()
        {
            return $this->email;
        }
    
        public function setEmail($email)
        {
            $this->email = $email;
        }
    
        public function getPassword()
        {
            return $this->password;
        }
    
        public function setPassword($password)
        {
            $this->password = $password;
        }
    }
    

    doc for validation : http://symfony.com/doc/current/book/validation.html

    NOTE : there is no need to add some validation on password entity property, the repeatedType done it for you

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

Sidebar

Related Questions

I have a code snippet that looks like this: [tableView beginUpdates]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
My code snippet looks like this: I want to delay the text in the
It looks like this snippet of code doesn't work unless I include the first
I have a Fortran77 snippet that looks like this: DO 1301 N=NMLK-2,2,-1 Some code...
I am using this code snippet to add KeyDown event handler to any element
I'm running a scheduling algorithm with a garbage collection snippet that looks like this:
So, say I have an array that looks like this: t = [ [
I am learning python, now, i came across a code snippet which looks like
My Colmodel in javascript looks like this jQuery(#testGrid).jqGrid( //Some code colModel: [ { name:
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)

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.