I am trying to make a search by date form to work on Symfony 2.3. I have an entity with a few fields (5) the name of the entity is Schedule and two of this fields are datetime, for start date time and end Date time. I want to search by dates, but it is giving me headaches. I have this action:

    public function indexAction(Request $request)
    //time form creation
    $aSchedule = new Schedule();
    $dateTimeForm = $this->createFormBuilder($aSchedule)
            ->add('startDateTime', 'datetime')
            ->add('endDateTime', 'datetime')
            ->add('search', 'submit')
    //getting the formr using post

    if ($dateTimeForm->isSubmitted()){
        echo 'Submited';
    if ($dateTimeForm->isValid()){
        echo 'Is Valid';

I have show the form in template like this:

        <form action="{{ path('osd_sch_homepage') }}" method="post" 
        {{ form_enctype(dateTimeForm) }} >
        <div id="start-date-time">
            {{ form_label(dateTimeForm.startDateTime) }}
            {{ form_errors(dateTimeForm.startDateTime) }}
            {{ form_widget(dateTimeForm.startDateTime) }}                    
        <div id="end-date-time">
            {{ form_label(dateTimeForm.endDateTime) }}
            {{ form_errors(dateTimeForm.endDateTime) }}
            {{ form_widget(dateTimeForm.endDateTime) }}            
            {{ form_widget( }}

Now in the action every time in send the form the "$dateTimeForm->isSubmitted()" works fine, but the "$dateTimeForm->isValid()" is not getting true, I mean is never going the "echo 'Is Valid';". what am I doing wrong? Thank you in advanced. Abel Guzman

 2 条回答