0

I am struggling with the custom validation in symfony/doctrine. I made three widgets:

  • sfWidgetFormDateTimeAmPm,
  • sfWidgetFormDateAmPm and
  • sfWidgetFormTimeAmPm to add the am/pm to the standard 24 hours date/time format.

Similar I created three validator classes:

  • sfValidatorDateTimeAmPm,
  • sfValidatorDateAmPm and
  • sfValidatorTimeAmPm.

I added this classes to my doctrine basic class like this:

class EventForm extends BaseEventForm {

 public function configure(){
    parent::configure();
    /* custom widget */
    $this->widgetSchema['start_date']            = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['end_date']              = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['repeat_end_after_date'] = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['created_at']            = new sfWidgetFormDateTimeAmPm();
    $this->widgetSchema['updated_at']            = new sfWidgetFormDateTimeAmPm();

    $this->setValidators['start_date']            = new sfValidatorDateTimeAmPm();
    $this->setValidators['end_date']              = new sfValidatorDateTimeAmPm();
    $this->setValidators['repeat_end_after_date'] = new sfValidatorDateTimeAmPm(array('required' => false));
    $this->setValidators['created_at']            = new sfValidatorDateTimeAmPm();
    $this->setValidators['updated_at']            = new sfValidatorDateTimeAmPm();

    $this->validatorSchema->setPostValidator(
        new sfValidatorDoctrineUnique(array('model' => 'Event', 'column' => array('id')))
    );
    $this->widgetSchema->setNameFormat('event[%s]');
    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

... but it does not work. Could someone advice me. I have no clue, what it did wrong or what I have forgotten to do.

Thanks Andreas

1 Answer 1

1

$this->setValidators['field'] is wrong, you want $this->validatorSchema['field'] = new WhateverValidator().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.