1

There are a number of answers on this forum for getting a front-end form to have a DateTime field that splits date and time into separate fields; It's not working for me.

If I strip back to absolute basics - hardcoded, as a test:

<input type="hidden" id="endDate" name="fields[endDate]" value="2017-12-30 02:15:00" />

Works, and a date & time is stored in the back-end field, displaying correctly.

But, if I try to split it so the date and time fields are separate (so that I can use a date picker on one and a select drop down on the other) - it doesn't save a value into the field. Even stripped back to hard-coded hidden fields...

<input type="hidden" id="endDate" name="fields[endDate][date]" value="2017-12-30" />

<input type="hidden" id="endTime" name="fields[endDate][time]" value="02:15:00" />

What am I doing wrong? The is the same format that works in the Craft back-end...

1

I suspect it might be your values. Try testing with this hard coded in and see if it works:

<input type="hidden" id="endDate" name="fields[endDate][date]" value="12/30/2017" />
<input type="hidden" id="endTime" name="fields[endDate][time]" value="2:15 AM" />

I always reference what's on this StraightUpCraft guide, and I try to be as exact as possible to the examples. You can also just inspect date fields inside a saved entry in the CMS to see what the values look like and mimic that on the front end.

| improve this answer | |
0

I recently did this using a field called expirDate:

<input type="date" name="expiryDate" id="expiryDate" class="form-control">

Can you give that a try?

| improve this answer | |
  • How do you set value? – carlcs Jul 6 '17 at 14:11
  • I can't rely on a date field type unfortunately as browser support is still spotty, and it wouldn't allow me to select the time either. – Matt Wilcox Jul 6 '17 at 14:12

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.