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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:06:01+00:00 2026-06-02T07:06:01+00:00

Im sure this must be a RTM question, but I must be looking in

  • 0

Im sure this must be a RTM question, but I must be looking in the wrong places. In symfony 1.4 I used post validator callbacks quite a lot. For example checking that start and end dates were in the correct order. I am developing an app in Silex but cant figure out how to add similar functionality as a validator. This is what I am working with (basically):

$app['form.example'] = function ($app) {
    $constraints = new Assert\Collection(array(
        'date1' => new Assert\Date(),
        'date2' => new Assert\Date(),
    ));

    $builder = $app['form.factory']->createNamedBuilder('form', 'example', array(), array('validation_constraint' => $constraints));

    return $builder
        ->add('date1', 'date')
        ->add('date2', 'date')
        ->getForm();
};

I can put my own validation test in the ‘process form’ part, like: if ($form->isValid() && --my datetest--) but it doesnt feel right to me there.

Any help? Thanks!

  • 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-02T07:06:02+00:00Added an answer on June 2, 2026 at 7:06 am

    I guess you can use form events for this kind of thing; certainly for Symfony2, so I assume Silex too? There’s a cookbook article about using it to generate dynamic forms:

    http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html

    Some useful detail in another SO question:

    Description of Symfony2 form events?

    Could have sworn I had a SO discussion about this with someone before but I cannot find the question. I used BIND_CLIENT_DATA to calculate some form fields in some code a while back; I’ll see if I can dig it out.

    EDIT

    Okay, I found something but I’m modifying this from Symfony code so I’m not 100% on this but it might be a starting point (I hope):

    $builder->addEventListener(FormEvents::BIND_NORM_DATA, function($event) {
        // your form data
        $data = $event->getData();
    
        // get date objects - if you cannot dereference this way try getters
        $d1 = $data['date1'];
        $d2 = $data['date2'];
    
        // naive comparison :)
        $isCorrectDateOrder = $d1->getTimestamp() < $d2->getTimestamp();
    
        // check the comparison
        if (!$isCorrectDateOrder) {
            // trouble... create and add a FormError object to the form
            $event->getForm()->get('date1')->addError(new \Symfony\Component\Form\FormError('uh oh...'));
        }
    });
    

    Hope this helps 🙂

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

Sidebar

Related Questions

I'm sure this must be something simple, but I can't quite work out what's
I'm sure this must be a common question, but I haven't found an answer
I am sure this must be a common question but I cannot find it
I'm sure this must be possible, but I can't find out how to do
I'm sure this must have been asked before, but I can't find it. Can
I'm sure this is a relatively simple question, and there must be a good
I am sure that this kind of questions must have been asked before, but
I am sure there must be a relatively straightforward way to do this, but
Pretty sure this question counts as blasphemy to most web 2.0 proponents, but I
Not sure this is a programming question, but we use LaTeX for all our

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.