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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:51:30+00:00 2026-06-10T16:51:30+00:00

I don’t know why, but I remembered that when you have a symfony form

  • 0

I don’t know why, but I remembered that when you have a symfony form with required fields not rendered, the isValid function do not check for them.

I mean it only check if the widget got a value when you use it. And it seem in my current project that it is wrong.

Is there a setting or something allowing to do this ?

Edit : Here is the form :

    class DemandeForm extends BaseDemandeForm
    {
  public function configure()
  {
    $this->widgetSchema['DEMANDE_DESC']         = new sfWidgetFormTextarea();
    $this->validatorSchema['DEMANDE_DESC']      = new sfValidatorString(array('required' => true),
    array("required" => str_replace('$1','Description de la demande',MessagePeer::getFrameworkMessageFromNum(7))));

    $this->validatorSchema['DEMANDE_LIB']      = new sfValidatorString(array('required' => true),
    array("required" => str_replace('$1','Libelle de la demande',MessagePeer::getFrameworkMessageFromNum(7))));

    $this->widgetSchema['TIERS_ID']         = new crfcWidgetAutocomplete();
    $this->validatorSchema['TIERS_ID']      = new sfValidatorString(array('required' => true),
    array("required" => str_replace('$1','Tiers',MessagePeer::getFrameworkMessageFromNum(7))));

    $bat_choices = $this->getOption('bat_choices');
    $this->widgetSchema['BAT_CODE']         = new sfWidgetFormChoice(array('choices' => $bat_choices , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['BAT_CODE']      = new sfValidatorChoice(array('choices' => array_keys($bat_choices),'required' => false)
    );

    $local_choices = $this->getOption('local_choices');
    $this->widgetSchema['LOCAL_CODE']       = new sfWidgetFormChoice(array('choices' => $local_choices, 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['LOCAL_CODE']    = new sfValidatorChoice(array('choices' => array_keys($local_choices),'required' => false)
    );

    $site_choices = $this->getOption('site_choices');
    $this->widgetSchema['SITE_CODE']       = new sfWidgetFormChoice(array('choices' => $site_choices, 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['SITE_CODE']    = new sfValidatorChoice(array('choices' => array_keys($site_choices),'required' => false)
    );

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('FONCTIONS',true);
    $this->widgetSchema['FONCTION_EVAL_NUMINT']         = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['FONCTION_EVAL_NUMINT']      = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
    array("required" => str_replace('$1','Fonction demandeur',MessagePeer::getFrameworkMessageFromNum(7))));

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('CIRCONSTANCE',true);
    $this->widgetSchema['CIRCONSTANCE_EVAL_NUMINT']       = new sfWidgetFormChoice(array('choices' => $ress, 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['CIRCONSTANCE_EVAL_NUMINT']    = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
    array("required" => str_replace('$1','Circonstance de la demande',MessagePeer::getFrameworkMessageFromNum(7))));

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('TRAVAUX',true);
    $this->widgetSchema['CATEGORIE_EVAL_NUMINT']         = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['CATEGORIE_EVAL_NUMINT']      = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
        array("required" => str_replace('$1','Catégorie de travaux',MessagePeer::getFrameworkMessageFromNum(7)))
    );

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('QUALIFICATION',true);
    $this->widgetSchema['QUALIFICATION_EVAL_NUMINT']         = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['QUALIFICATION_EVAL_NUMINT']      = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => true),
        array("required" => str_replace('$1','Qualification',MessagePeer::getFrameworkMessageFromNum(7)))
    );

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('PROGRAMME',true);
    $this->widgetSchema['PROGRAMME_EVAL_NUMINT']         = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['PROGRAMME_EVAL_NUMINT']      = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => true),
            array("required" => str_replace('$1','Programme',MessagePeer::getFrameworkMessageFromNum(7)))
            );

    $ress = Array(""=>"") + EnumereValeurPeer::getByType('SUPPORT',true);
    $this->widgetSchema['SUPPORT_EVAL_NUMINT']         = new sfWidgetFormChoice(array('choices' => $ress , 'expanded' => false, 'multiple' => false));
    $this->validatorSchema['SUPPORT_EVAL_NUMINT']      = new sfValidatorChoice(array('choices' => array_keys($ress),'required' => false),
    array("required" => str_replace('$1','Support',MessagePeer::getFrameworkMessageFromNum(7))));

    $this->widgetSchema['COMMENTAIRE']         = new sfWidgetFormTextarea();
    $this->validatorSchema['COMMENTAIRE']      = new sfValidatorString(array('required' => false));


    $this->widgetSchema['DEMANDE_DTDEM']                    = new myWidgetFormRichDate();
    $this->validatorSchema['DEMANDE_DTDEM']                 = new sfValidatorDate(array('required' => true, 'date_format'=>'@(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})@'),
        array('required'=> str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(7)),
        'bad_format' => str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(19)),
        'invalid' => str_replace('$1','Date de la demande',MessagePeer::getFrameworkMessageFromNum(19))));

    $this->widgetSchema['DEMANDE_DTFIN']                    = new myWidgetFormRichDate();
    $this->validatorSchema['DEMANDE_DTFIN']                 = new sfValidatorDate(array('required' => true, 'date_format'=>'@(?P<day>\d{2})/(?P<month>\d{2})/(?P<year>\d{4})@'),
        array('required'=> str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(7)),
        'bad_format' => str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(19)),
        'invalid' => str_replace('$1','Date de fin des travax souhaitée',MessagePeer::getFrameworkMessageFromNum(19))));

    $this->widgetSchema['DEMANDE_ACCESSIBILITE']            = new sfWidgetFormInputCheckbox();
    $this->validatorSchema['DEMANDE_ACCESSIBILITE']         = new sfValidatorBoolean(array('required' => false));

    $this->widgetSchema['DEMANDE_URGENT']                   = new sfWidgetFormInputCheckbox();
    $this->validatorSchema['DEMANDE_URGENT']                = new sfValidatorBoolean(array('required' => false));

    $this->widgetSchema['DEMANDE_INCENDIE']                 = new sfWidgetFormInputCheckbox();
    $this->validatorSchema['DEMANDE_INCENDIE']              = new sfValidatorBoolean(array('required' => false));

    $this->validatorSchema->setOption('allow_extra_fields' , true);
    $this->validatorSchema->setOption('filter_extra_fields' , false);
  }


}

Edit 2 :

The question is : is it normal than the DEMANDE_DTDEM field required, raise a required form field error, whereas he hadn’t been rendered ?

Shouldn’t a form field be validated only when he was used ?

  • 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-10T16:51:31+00:00Added an answer on June 10, 2026 at 4:51 pm

    Yes, it’s the normal behaviour. Fields VALIDATION has nothing to do with rendering.
    If you don’t want to render a widget you must explicitly remove both widget and validator (with unset or useFields).

    If you define a widget and a validator (like in your case), but you don’t call to $form['DTDEM']->render(), the value will be always empty.

    IT’S VERY IMPORTANT THAT YOU UNDERSTAND THAT. In this case, the field is required, and then become that error, but if it wasn’t required, the $form->save() method will always clean the value of the object in your database!

    NEVER leave the widgets unrendered. You should do some echo $form while debugging to see what widgets are configured, and if you don’t want some of them, just remove them in the form configure() method (as I said, with unset or useField)

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

Sidebar

Related Questions

Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know if this question is trivial or not. But after a couple
Don't know why this is happening, but after submitting a form via JS (using
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know why but I can't find a solution to this. I have 3
DON'T ASK WHY but... I have a regex that needs to be case insensitive
don't know better title for this, but here's my code. I have class user
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't really know how to formulate the title, but it should be pretty obvious

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.