We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Format Date Fields in channel:form... how?

How Do I?

JCOGS Design's avatar
JCOGS Design
71 posts
about 6 years ago
JCOGS Design's avatar JCOGS Design

I’m sure it is in the documentation somewhere, but could someone explain to me how to define a date format for a date field within a channel form?

Using {field:date_field} provides a date field that is formatted (using EE date format) %j/%n/%Y %G:%H %A - I want it to be %j %F %Y.

I have tried putting the field in manually but it appears the standard date formatting doesn’t work within channel:form tags - putting in {date_field format="%j %F %Y"} results in EE dumping the tag itself into the HTML, whereas using {date_field} gives the Unixtime value for the date.

Any guidance on this point would be most appreciated!

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
about 6 years ago
Robin Sowell's avatar Robin Sowell

The channel form is definitely its own beast. You want to allow the form values to use the default format. So if you’re putting the value in the form, what {field:date_field} gives you should be what you want. If you manually try to alter it, it may fail validation or worse, pass validation but go in incorrectly.

When it validates and translates a data into a timestamp, it does so in part based on the user’s date format (which tells it where to expect a month, a day, and a year) and the structured date sent in post.

Does that make sense? Compare the fields to what you see in the control panel publish. If it’s using the same format, that’s the format you should submit it in.

You can change that up with your individual format settings, but you don’t want to change it up by manually manipulating the date.

(You could do it with say an extension to manually manipulate it back to what’s expected, but that’s likely overkill. And if you just want it for display and not for the form field value, then of course, it’s moot and let me know and I’ll see what I can brainstorm.)

       
JCOGS Design's avatar
JCOGS Design
71 posts
about 6 years ago
JCOGS Design's avatar JCOGS Design

Hi Robin

Thanks for the reply. I’m intrigued: there is (as far as I know) no way to set the date format for a date field in CP.

The {field:date_field} value is indeed displaying in the form in the same format as shown when you edit the date in the CP version of the entry, so I’m with you so far. But since there appears to be no way to modify that representation, does this mean the only way to edit the date in a channel:form is to have the date in that format (e.g. with the hh:mm appended to the date)?

I have worked out that I could bypass the whole channel:form thing completely and write something to do the same, but as you say it is a bit of a waste of my time to do so if I can get the format to show right using the EE alternative. Maybe I’m just missing something obvious about how to get the field format to bend to my will…?

Do let me know if you have any futher thoughts.

       
Robin Sowell's avatar
Robin Sowell
13,158 posts
about 6 years ago
Robin Sowell's avatar Robin Sowell

It’s in your profile settings, but it’s not going to help you on this one. You can change the format a la mm/dd/yyyy to dd/mm/yyyy (which you can see why it’s important the basic format of the date submitted is consistent with what you’ve told EE you’re using for dates), but you can’t ditch the minutes and hours. Though- you can ditch seconds. And while poking I remembered you can actually override that in a form, but again, not helping with the hours/minutes.

I don’t think we’d want to ditch minutes/hours universally and really what would be nice here is a setting on date fields to allow you to exclude showing minutes/hours and set defaults. But… that doesn’t help us now.

I played around and if you just don’t submit the hours/minutes, it doesn’t screw anything up and just defaults to 12 am (which makes sense). And I’m pretty sure I can get ‘now’ showing with no hours and minutes as a default in a new form entry. But- edits are going to show hours/minutes and we lose the date picker, which is dead set on putting in hours/minutes.

Do you need edits and do you need the date picker working? I’d miss the date picker myself, so I’m thinking ‘yes’.

       
JCOGS Design's avatar
JCOGS Design
71 posts
about 6 years ago
JCOGS Design's avatar JCOGS Design

Thanks for the extra info.

The idea is to allow editing of a date for an event (in this case parties / weddings and so on) but since the date is not actually an invite (just an indication of what day it is) the time part is not needed. Yes a date-picker would be good, but there is no need for user to type/edit the date if the date picker works.

So the ideal would be the ability to use date formatting in the form (e.g. format=”%j %F %Y” or some such). Alternatively the ability to just pop up the date-picker without showing the edit field / result - the channel:form is being used via AJAX, so it could simply trigger the AJAX submission when a date is chosen to update the field.

I imagine that channel:form will be reworked one day to work in a more consistent way with the rest of EE, but in the interim I hope to find a work-around that gets this requirement sorted out fairly quickly.

If bending EE to behave nicely is not an option, do you know if anyone has done anything to fix via add-ons? I cannot be the only person who has hit this issue…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.