1

I'm working on an inherited site where I have a sprout form and am adding additional fields. I have added a date/time field to the form with the settings in this screenshot.

enter image description here

In my template where all other fields are working I have added the following.

{{ craft.sproutForms.displayField('contact.targetProjectDate') }}

This field does not display and there is nothing in the source either.

Please advise

1

In the end I switched it to a default text field and used jQuery datepicker.

| improve this answer | |
  • This is the simplest solution. If you were to expand the Field dropdown it would show the Date/Time field in a 'Custom Fields' dropdown. Custom Fields require that you either write an integration to add support or update your base templates with custom HTML to handle the DateTime field. – Ben Parizek Nov 30 '17 at 1:34
0

Not exactly a direct answer, but this is where my first search started me.

To save a Date/Time field into craft using a jQuery dateTime picker, you can create a small plugin and place this in the init method of the primay plugin file (Craft 2x).

MyPluginFile.php

public function init()
{
    parent::init();

    craft()->on('sproutForms.onBeforeSaveEntry', function (Event $event) {
        if (craft()->request->isCpRequest()) {
            // Entry was saved from within the CP so we can ignore it.
        } else {
            if ($event->params['isNewEntry']) {
                $entry = $event->params['entry'];

                // Get the current time zone from the system.
                date_default_timezone_set(craft()->timezone);

                $entry->setContentFromPost(array(
                    'eventDate' => date('Y-m-d', strtotime(craft()->request->getPost('fields.eventDate'))),
                    'startTime' => date('Y-m-d H:i:s', strtotime(craft()->request->getPost('fields.startTime'))),
                    'endTime' => date('Y-m-d H:i:s', strtotime(craft()->request->getPost('fields.endTime'))),
                ));
            }
        }
    });
}
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.