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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:26:35+00:00 2026-05-13T01:26:35+00:00

I am using Symfony 1.2.9, and I have a form that contains two date

  • 0

I am using Symfony 1.2.9, and I have a form that contains two date fields:

start_date AND end_date.

I want to impose the following validation criteria for the ‘start_date’ field:

  1. i). CANNOT be less than todays date
    ii). CANNOT be greater than end_date
    iii). CANNOT be more than 1 month
    away

For end_date, I want the following restrictions:

  1. i). Cannot be more than 3 months
    away from today

I have written a post validator check as follows:

$today = date('Y-m-d');

//post validator check to make sure end date > start date
$this->validatorSchema->setPostValidator(
 new sfValidatorAnd(array(
    new sfValidatorSchemaCompare('start_date', '<', 'end_date',
      array('throw_global_error' => true),
      array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")<br />')
       ),

    new sfValidatorSchemaCompare('start_date', '<', $today,
      array('throw_global_error' => true),
      array('invalid' => 'The start date ("%left_field%") cannot be earlier than today\'s date: ('.$today.')<br />')
       ),

    new sfValidatorSchemaCompare('end_date', '>', $today,
      array('throw_global_error' => true),
      array('invalid' => 'The end date ("%left_field%") cannot be before today\'s date ("%right_field%")<br />')
       )
    )
   )
 );

However, this is not working – i.e. I have not found a way yet to enforce restrictions based on todays date, or offsets from today’s date.

A solution would be very welcome.

  • 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-13T01:26:36+00:00Added an answer on May 13, 2026 at 1:26 am

    Personally for code readability I’d move your post validation checks into a postValidate method on your form, vis:

    public function configure()
    {
      // your normal configuration stuff goes here
    
      // set up your post validator method
      $this->validatorSchema->setPostValidator(
        new sfValidatorCallback(array(
          'callback' => array($this, 'postValidate')
        ))
      );
    }
    

    Then you can do something like the following:

    public function postValidate($validator, $values)
    {
      $today = date("Y-m-d");
    
      if (strtotime($values["start_date"]) < strtotime($today))
      {
        $error = new sfValidatorError($validator, "Start date cannot be before than today");
        throw new sfValidatorErrorSchema($validator, array('start_date' => $error));
      }
    
      if (strtotime($values["start_date"]) > strtotime($values["end_date"]))
      {
        // throw a similar validation error here
      }
    
      // etc...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the Generics Tutorial. Thanks to Michael's answer! It isn't… May 13, 2026 at 8:47 am
  • Editorial Team
    Editorial Team added an answer For index 12. Indexes 0--11 are the actual months in,… May 13, 2026 at 8:47 am
  • Editorial Team
    Editorial Team added an answer You would still have to restart the services. May 13, 2026 at 8:47 am

Related Questions

I am using Symfony 1.2.9 (with Propel ORM), to build a website. I have
I am using Symfony 1.2.9 (with Propel ORM) on a website I am building.
I am using Symfony 1.2 with the sfDoctrinePlugin. I couldn't find any command to
I am using Propel 1.2 in a Symfony 1.0 project, with PostgreSQL db. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.