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?

  • 1
    It might be helpful to show us your start variable Commented Nov 8, 2017 at 13:34
  • 1
    What does {{ dump(start) }} output?
    – Brad Bell
    Commented Nov 8, 2017 at 21:24
  • @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]). Commented Nov 13, 2017 at 15:46
  • @BradBell this outputs: array (size=1) 'date' => string '08/11/2017' (length=10) Commented Nov 13, 2017 at 15:46
  • 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") Commented Nov 13, 2017 at 15:49


Your Answer

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