0

I'm trying to use a datetime type

    $builder->add('start_date', 'datetime', array(
        'widget' => 'single_text',
        'input'  => 'string'
    ));

my form date format is RFC 3339

    [start_date] => '2016-01-04T16:01:25+00:00'

Error

    The parsed date was invalid, The separation symbol could not be found, Unexpected data found., Unexpected data found., Unexpected data found., Unexpected data found., Unexpected data found., Data missing

seems that datetime type is only expecting date as string with format 2016-01-04 16:01:25 and this format can't be changed from the form type configs

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php#L171

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php#L68

wondering if thats the desired behavior or an issue

Note

both format and date_format options will work on the view data rather than the input data.

stack trace

at DateTimeToStringTransformer ->reverseTransform ('2016-01-04T16:01:25+0000') 
in vendor/symfony/symfony/src/Symfony/Component/Form/ReversedTransformer.php at line 46   + 
at ReversedTransformer ->transform ('2016-01-04T16:01:25+0000') 
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 1087   + 
at Form ->modelToNorm ('2016-01-04T16:01:25+0000') 
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 352   + 
at Form ->setData ('2016-01-04T16:01:25+0000') 
in vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php at line 57   + 
at PropertyPathMapper ->mapDataToForms (array('start_date' => '2016-01-04T16:01:25+0000')), object(RecursiveIteratorIterator)) 
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 386   + 
at Form ->setData (array('start_date' => '2016-01-04T16:01:25+0000')) 
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 478   + 
at Form ->initialize () 
in vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php at line 226   + 
at FormBuilder ->getForm () 
in vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php at line 40   + 
at FormFactory ->create ('app_test_form', array('start_date' => '2016-01-04T16:01:25+0000')), 'items' => array()), array()) 
in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 282   + 
at Controller ->createForm ('app_test_form', array('start_date' => '2016-01-04T16:01:25+0000')), 'items' => array())) 
in src/AppBundle/Controller/DummyController.php at line 39   + 
7
  • 1
    Do you have php5-intl extension ? Commented Jan 5, 2016 at 7:58
  • Did you actually try the format option? Please note that the view data is both the data that is shown to the user as well as the data entered by the user. If you use your form in an API, the view data is the data sent by the consumer of your API. Commented Jan 5, 2016 at 8:02
  • @xabbuh i understand except that the model transformer get triggered first and it triggers the error please check the symfony code Commented Jan 5, 2016 at 11:22
  • Looks like something is going wrong for you then. When does the model transformer get triggered with the wrong data? When the form is created or when the request is submitted? And can you show the complete stack trace of that error? Commented Jan 5, 2016 at 11:26
  • @xabbuh when the form is created Commented Jan 5, 2016 at 12:22

2 Answers 2

0
$builder->add('start_date', 'datetime', array(
        'widget' => 'single_text',
        'input'  => 'string',
        'date_format' => 'yyyy-MM-dd  HH:mm:ss'
    ));

try this one, hope will help full to you

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

1 Comment

both format and date_format options will work on the view data rather than the input data.
0

It seems you also need to add format

Refer details here

wondering if thats the desired behavior or an issue

This seems to be behaviour as per documentation, refer line 140

// Change the input to a HTML5 date input if
    //  * the widget is set to "single_text"

    //  * the format matches the one expected by HTML5

    //  * the html5 is set to true


add('start_date', 'date', array(
        'widget' => 'single_text',
        'format' => 'c'))

refer question

1 Comment

this is a view format rather than a model format

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.