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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:07:17+00:00 2026-05-14T03:07:17+00:00

public function configure() { $this->widgetSchema[‘start_date’] = new sfWidgetFormInput(); $this->widgetSchema[‘end_date’] = new sfWidgetFormInput(); $this->validatorSchema->setPostValidator( new

  • 0
public function configure()
  {
    $this->widgetSchema['start_date'] = new sfWidgetFormInput();
    $this->widgetSchema['end_date'] = new sfWidgetFormInput();


    $this->validatorSchema->setPostValidator( new sfValidatorOr ( array( 
                                                    new sfValidatorAnd( array
                                                          (new sfValidatorSchemaCompare('start_date', sfValidatorSchemaCompare::NOT_EQUAL, null), 
                                                           new sfValidatorSchemaCompare('end_date', sfValidatorSchemaCompare::EQUAL, null)
                                                    )), 
                                                    new sfValidatorSchemaCompare('start_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'end_date', 
                                                    array('throw_global_error' => false), array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")')))));
  }

I’ve got following input dates which I want to check if the end date isn’t before the start date:

Input: Start => 31/03/10 End=> 07/03/10
Output: The start date (2010-03-31) must be before the end date (2010-03-07)

Can you in some way change the date output? I need the error message to set the date format the same as the input.
Also my input fields are set with the wrong date format when the error appears.

Tried several things, but no luck at this moment. Didn’t find a solution or information on symfony it self.

I’m using symfony version 1.2.11

  • 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-14T03:07:17+00:00Added an answer on May 14, 2026 at 3:07 am

    I found a the solution together with a colleague.

    After some tryouts, we found the solution to my initial problem. Instead of using that post validator, we wrote are own validator.

    class StartBeforeEndDateValidator extends sfValidatorBase {
    
      public function configure($options = array(), $messages = array()) {
        parent::configure($options, $messages);
        $this->addMessage('Invalid_daterange', 'Start date (%start%) must be before End date (%end%)!');
      }
    
      public function doClean($values) {
    
        sfContext::getInstance()->getConfiguration()->loadHelpers('Date');
    
        $timestampStart = sfContext::getInstance()->getI18N()->getTimestampForCulture($values['start_date'], sfContext::getInstance()->getUser()->getCulture());
        $timestampEnd = sfContext::getInstance()->getI18N()->getTimestampForCulture($values['end_date'], sfContext::getInstance()->getUser()->getCulture());
    
        if(format_date($timestampStart) > format_date($timestampEnd)){
          throw new sfValidatorError($this, 'Invalid_daterange', array('start' => $values['start_date'], 'end' => $values['end_date']));
        }
    
      }
    
    }
    

    Usage of the validator in the symfony form:

      public function configure() {
        $this->widgetSchema['start_date'] = new sfWidgetFormInput();
        $this->widgetSchema['end_date'] = clone $this->widgetSchema['start_date'];
    
        $this->validatorSchema['start_date'] = new DateValidator();
        $this->validatorSchema['end_date'] = clone $this->validatorSchema['start_date'];
    
        $this->validatorSchema->setPostValidator(new StartBeforeEndDateValidator());
      }
    

    This was the solution to have always the same date format when it’s being validated and when the validation is trigger with an error, the format of the date is correctly returned in the same date format as it was set.

    Now one other “problem” that we encountered was when the save happened, the date format wasn’t right for mysql. So we override the save function in our symfony form and apply the right date format.

    example:

      public function save($con = null){
    
        $var = new Object();
    
        if($this->taintedValues['id']!= ""){
          $var->setId($this->taintedValues['id']);
        }
        $var->setStartDate(DateUtils::getIsoDateForCulture($this->taintedValues['start_date']));
        $var->setEndDate(DateUtils::getIsoDateForCulture($this->taintedValues['end_date']));
        $var->setIcpm($this->taintedValues['icpm']);
    
        $var->save($con);
    
      }
    

    So once the validation is valid, it will perform the save function and set the right date format before actually save it into the database.

    Hope that this is helpful for other people who had this problem.

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

Sidebar

Related Questions

in the tutorial i can use either: public function configure() { $this->setWidgets(array( 'type' =>
public function create($tableName, $userInput) { $this->db->insert($tableName, $userInput); return $this->db->affected_rows(); } As you see, $this->db->affected_rows();
public function action_adicionar_item() { $lista_item_pedido = array(); $x = 0; if(Session::has('lista_item_pedido')) { foreach(Session::get('lista_item_pedido') as
public function getItemsCollection($useCache = true) { if (is_null($this->_items)) { $this->_items = Mage::getModel('sales/quote_item')->getCollection(); $this->_items->setQuote($this); }
public function bmdToStr(bmd:BitmapData,width:int,height:int):String { var encoder:JPEGEncoder = new JPEGEncoder(); var encBytes:ByteArray = encoder.encode(bmd); return
public function index() { $this->redirect('/'); } I will just go insane soon... How can
I'm using Symfony 1.2 in a standard Propel form class. public function configure() {
public function __construct($input = null) { if (empty($input)){ return false; } and then there's
public function test(){ $data = ORM::factory('testdata')->find_all(); Table::factory() ->set_body_data($data) ->set_row_titles('id') ->set_column_titles(Table::AUTO) ->set_callback('format_row', 'row') ->render(true); $this->template->title
Public Function CastToT(Of T)(ByVal GenericType(Of Object) data) As GenericType(Of T) Return DirectCast(data, GenericType(Of T))

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.