0

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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.