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

  • Home
  • SEARCH
  • 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 8639011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:53:24+00:00 2026-06-12T10:53:24+00:00

I’m using Silex for a small project, but I’m not sure how to validate

  • 0

I’m using Silex for a small project, but I’m not sure how to validate two matching password fields, also check for the uniqueness of an email using a database connection. I haven’t been able to figure it out in SF2 docs.

Possible someone can give me a hint or sample?

Thanks in advance

if ('POST' === $user->getMethod()) {

    $constraint = new Assert\Collection(array(
        'name' => array(new Assert\NotBlank(array('message' => 'Name shouldnt be blank'))),
        'username' => array(new Assert\NotBlank(), new Assert\MinLength(3)),
        'email' => array(new Assert\NotBlank(), new Assert\Email()),
        'password' => array(new Assert\NotBlank(), new Assert\MinLength(6)),
        'password2' => array(new Assert\NotBlank(), new Assert\MinLength(6)),
        'terms' => array(new Assert\True()),
    ));

    $errors = $app['validator']->validateValue($user->request->all(), $constraint); 

    if (!count($errors)) {
    //do something
    }
}
  • 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-12T10:53:27+00:00Added an answer on June 12, 2026 at 10:53 am

    I see in the comments that you already switched to Sf2 forms. I guess you found the RepeatedType field, which is best for the repeated password field of a registration form – it has a built-in check to verify that the two values match.

    Your other problem is checking the uniqueness of an email address. Here’s the relevant part of my registration form:

    <?php
    
    namespace Insolis\Form;
    
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;
    use Symfony\Component\Validator\Constraints as Assert;
    use Symfony\Component\Validator\ExecutionContext;
    
    class RegisterType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $app = $options["app"];
    
            $builder->add("email", "email", array(
                "label"         =>  "E-mail address",
                "constraints"   =>  array(
                    new Assert\NotBlank(),
                    new Assert\Email(),
                    new Assert\Callback(array(
                        "methods"   =>  array(function ($email, ExecutionContext $context) use ($app) {
                            if ($app["user"]->findByEmail($email)) {
                                $context->addViolation("Email already used");
                            }
                        }),
                    )),
                ),
            ));
        }
    
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            parent::setDefaultOptions($resolver);
            $resolver->setRequired(array("app"));
        }
    
        public function getName()
        {
            return "register";
        }
    }
    

    Notes:

    • $app is injected so I have access to the dependency injection container
    • $app["user"] is my User table via KnpRepositoryServiceProvider
    • $app["user"]->findByEmail returns null or a user record
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.