<p>I want to use the built-in Craft field macros to show a date field in a plugin template for filtering. </p>

<p>I can retrieve the submitted value on any submission (via GET) but how do I then prepopulate said date field with the previously submitted value? 
When I try to simply pass the submission into the value property I get an <code>Array to string conversion</code> error. </p>

<p>My plugin template code …</p>

<pre><code>{% set start = craft.request.getParam('start') %}    
{{ dump(start) }}
{{ forms.dateField({
    label: 'Start date',
    id: 'start',
    name: 'start',
    value: start }) }}
</code></pre>

<p>So my question is; is there anyway I can pass a value into the dateField that has been submitted via a POST or GET variable?</p>

CC BY-SA 3.0
2017-11-08T13:34:50.253Z
It might be helpful to show us your `start` variable
Robin Schambach
CC BY-SA 3.0
2017-11-08T21:24:19.630Z
What does `{{ dump(start) }}` output?
Brad Bell
CC BY-SA 3.0
2017-11-13T15:46:05.103Z
@RobinSchambach if I pass the value posted from the dateField element then I get  'date' => string '08/11/2017' (length=10) (where the above code example generates an input field with a name of `start[date]`).
Cole Henley
CC BY-SA 3.0
2017-11-13T15:46:36.293Z
@BradBell this outputs:

    `array (size=1)`
    `'date' => string '08/11/2017' (length=10)`
Cole Henley
CC BY-SA 3.0
2017-11-13T15:49:53.613Z
If i try to pass my date string as a value into {{ forms.dateField }} I get following error:

`Impossible to invoke a method ("localeDate") on a string variable ("11-08-2017")`
Cole Henley
CC BY-SA 3.0
2017-11-13T15:58:15.043Z
Thanks both - had overseen suggestion on Slack for following which works:

`value: now|date_modify(start.date)`
Cole Henley
CC BY-SA 3.0
2017-11-13T16:17:35.007Z
Hmmm, perhaps spoke to soon. 

Bizarrely when using the datefield it outputs dates in the following format DD-MM-YYYY. However, when I capture this value and try to output it in my template it is assuming that the DD is MM and MM is DD.

So for example, with a value of 12 November it posts `11-12-2017` as the GET value but in my template it is assuming this is 11 December.

Any further thoughts? Obviously some kind of mix-up with localisation but seems strange that the datefield is outputting in one kind and then the template is interpreting this value in a different way.

Thoughts?
Cole Henley
<plugin-development><localization><datetime>
Updating `{{ forms.dateField }}` value from GET variable
# Updating `{{ forms.dateField }}` value from GET variable

(Asked by: username_0 on 2017-11-08)

I want to use the built-in Craft field macros to show a date field in a plugin template for filtering. 
I can retrieve the submitted value on any submission (via GET) but how do I then prepopulate said date field with the previously submitted value? 
When I try to simply pass the submission into the value property I get an Array to string conversion error. 
My plugin template code …
{% set start = craft.request.getParam('start') %}    
{{ dump(start) }}
{{ forms.dateField({
    label: 'Start date',
    id: 'start',
    name: 'start',
    value: start }) }}

So my question is; is there anyway I can pass a value into the dateField that has been submitted via a POST or GET variable?

**Tags:** plugin-development, localization, datetime
> **Comments:**
> **username_1**: It might be helpful to show us your `start` variable  
> **username_2**: What does `{{ dump(start) }}` output?  
> **username_0**: @RobinSchambach if I pass the value posted from the dateField element then I get  'date' => string '08/11/2017' (length=10) (where the above code example generates an input field with a name of `start[date]`).  
> **username_0**: @BradBell this outputs:      `array (size=1)`     `'date' => string '08/11/2017' (length=10)`  
> **username_0**: If i try to pass my date string as a value into {{ forms.dateField }} I get following error:  `Impossible to invoke a method ("localeDate") on a string variable ("11-08-2017")`  
> **username_0**: Thanks both - had overseen suggestion on Slack for following which works:  `value: now|date_modify(start.date)`  
> **username_0**: Hmmm, perhaps spoke to soon.   Bizarrely when using the datefield it outputs dates in the following format DD-MM-YYYY. However, when I capture this value and try to output it in my template it is assuming that the DD is MM and MM is DD.  So for example, with a value of 12 November it posts `11-12-2017` as the GET value but in my template it is assuming this is 11 December.  Any further thoughts? Obviously some kind of mix-up with localisation but seems strange that the datefield is outputting in one kind and then the template is interpreting this value in a different way.  Thoughts?  

---

## 0 answers

