Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
58 posts Page 3 of 6
Previous 1, 2, 3, 4, 5, 6 Next
Can I use that for age validation. My website need to be for adult. Not because of pr0n but because of alchool.
Can I use that for age validation

The format of the date is fixed - yyyy-mm-dd.
So we can easily throw in a bit of PHP to create a validation routine.

Do let me know if you require any help with it.
Sent you a PM about it.
Beginning with v1.4RC, Couch ships with a native 'datetime' editable region -
Code: Select all
<cms:editable
    type='datetime'
    name='my_datetime'
    label='Date of Birth'
/> 

and an equivalent cms:input type for use with front-end forms -
Code: Select all
<cms:input 
    type='datetime'
    name='my_datetime'
/>

0.png
0.png (1.4 KiB) Viewed 14983 times


IMP:
The 'datetime' type comes bundled in with the 'data-bound form' addon (which, by default, comes disabled).
So, you'll need to enable the 'data-bound form' addon first for the 'datetime' to be available.

The process is the same as for all addons -
1. In the 'couch/addons' folder, you'll find 'kfunctions.example.php'.
Please rename it to make it 'kfunctions.php'
(if you have an older installation that has been upgraded to 1.4, you'll already have 'kfunctions.php' so this step can be skipped).

2. Finally, open kfunctions.php in a text editor and remove the comments (i.e. '//') from the following line in it (or put in the line if not present on an older installation) to make it -
Code: Select all
require_once( K_COUCH_DIR.'addons/data-bound-form/data-bound-form.php' );

That will enable data-bound form as well as the datetime region.


TIP:
While using this type on the front-end (either as plain cms:input or as 'bound' fields), you might find linking to the CSS used by it in the admin-panel useful -
Code: Select all
<link rel="stylesheet" href="<cms:show k_admin_link />addons/data-bound-form/datetime.css" type="text/css" media="screen" />

Of course, you are free to use your own style instead.

Parameters:
In addition to the parameters common to all editable regions (e.g. required, validator etc.), this new type supports the following parameters that can be used to tweak its appearance and behaviour -

format
Defines the order of the inputs representing 'year', 'month' and 'day'.
Acceptable values are 'dmy', 'ymd' or 'mdy'.
If none of the above are specified, the default value of 'mdy' is used.

fields_separator
Defines the character used to separate the 'year', 'month' and 'day' inputs.
Acceptable values are '/', '.' or '-'.
If none of the above are specified, the default value of '/' is used.

months
Can be used to define the names shown in the 'months' dropdown.
Acceptable string needs to have 12 comma-separated month-names e.g.
Code: Select all
<cms:editable
    type='datetime'
    name='my_datetime'
    label='Date of Birth'
    months='janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre'
/> 

If not specified, the default 'Jan', 'Feb' sequence is used.

allow_time
Can be used to allow input of time also by setting it to '1'.
1.png
1.png (1.52 KiB) Viewed 14983 times

The default value is '0' i.e. the inputs for time values are not shown.

am_pm
If the 'allow_time' parameter is set to '1', this parameter can be used to set if the 'hours' are showm in '24hrs' or the '12hrs am-pm' format.
The default value is '0' i.e. by default the '24 hrs' format is used.

default_time
Can be used to set the date/time displayed by default.
Valid values are
a. A blank
b. A string in the 'yyyy-mm-dd' or 'yyyy-mm-dd hh:mm:ss' format ( e.g. '2008-05-14' or '2008-05-14 02:08:45')
c. The special string '@current'. This will always display the current date/time.

minute_steps
If the 'allow_time' parameter is set to '1', this parameter can be used to set the interval between the values displayed in 'minutes' dropdown.
The default value is '10' i.e. the 'minutes' dropdown shows - 00, 10, 20, 30, 40, 50

show_labels
By default, the constituent inputs within the datepicker have a label below them showing their type e.g. 'YYYY', 'MM', 'DD' etc.
Setting this parameter to '0' will hide these labels.

This new native type can be used as an alternative to the datepicker discussed in the current thread.

Hope this helps.

Addendum:
Please see viewtopic.php?f=4&t=11006&p=29541#p29541 for using only the 'time' component of the 'datetime' editable region.
And to have a popup calendar to pick the date from it ?
What a great feature, thanks for that! Anyhow I get an error message when using it at my local server. I was trying to include it in my contact form.

ERROR: Tag "editable" has unknown type "datetime"
ERROR: Tag "input" has unknown type "datetime"

Update to 1.4 is already done twice to make sure :) - the data bound form is available in the addons folder. Pretty Urls are turned on if this could be of interest.

_ _ _ _ _
Just one more thing. After one month of very intensive drupal excursions I'm back to Couch and I more than happy with it then ever before. I finished my page redesign http://www.vienna-downtown.at in about 1.5 weeks which was not possible due stumbling through drupal with all it views and "must have" addons during one month. So if you read that and you are undecided give CouchCMS a try!
Hi Christoph,

Sorry I really should have mentioned it in the main post -
The 'datetime' type comes bundled in with the 'data-bound form' addon (which, by default, comes disabled).
So, you'll need to enable the 'data-bound form' addon first for the 'datetime' to be available.

The process is the same as for all addons -
1. In the 'couch/addons' folder, you'll find 'kfunctions.example.php'.
Please rename it to make it 'kfunctions.php'
(if you have an older installation that has been upgraded to 1.4, you'll already have 'kfunctions.php' so this step can be skipped).

2. Finally, open kfunctions.php in a text editor and remove the comments (i.e. '//') from the following line in it (or put in the line if not present on an older installation) to make it -
Code: Select all
require_once( K_COUCH_DIR.'addons/data-bound-form/data-bound-form.php' );

That will enable data-bound form as well as the datetime region.

Hope this helps.
thank you very much, everything working as intended - as usual :P
Outputting to mail produces different output than specified.
(I've specified dmy, but got output as ymd)
Tried couple variations to output specific element out of datepicker

<cms:show frm_appointtime_day />

didn't work out.
First - any ideas how to output same output as input is sorted, and to send to mail in same format?
Second - how can I output specific element to mail, such as day?!


Thank you KK, FIX IS BELOW
@lolsteamroller
All dates in Couch are internally stored in yyyy-mm-dd hh:mm:ss format.

You'll have to use the cms:date tag to output a date in whatever format you desire.
Please see http://www.couchcms.com/docs/tags-reference/date.html

I think that will answer both your questions.

Thanks.
Previous 1, 2, 3, 4, 5, 6 Next
58 posts Page 3 of 6