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 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
  • 1 View
  • 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

Related Questions

Using Symfony 1.3 I have a normal form-filter that is used to filter values
I am new to symfony. I have created a registration form using the code:
I have a problem to upload an image using Symfony. I have a form
Normally, we can have the Symfony Form to output the field errors using the
(I'm using Symfony2) I have a form that asks for the name and the
N00b question: I'm using Symfony with Doctrine. I have a form where I've added
I'm using symfony 1.4 doctrine. I have a code that can validate phone numbers
On Symfony 1.4.11 I have a boolean field that is set on a form
Using Symfony I created a form in the backend. I have a submit button,
we using symfony 1.0. We have an module work with Propel objects. The sql-querys

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.