Add a date form

Permalink Browser Info Environment
I have looked at designer-content for a couple of hours and I like it as I´m new to Concrete5.
It makes allot of things much more easy.
I do miss one thing.
I would like the ability to add a datetime field from a calender dropdown.
Since that function is included in the core it might not that hard to do (I don´t know!)

Something to think about in future upgrades.

Type: Discussion
Status: New
Erik74
View Replies: View Best Answer
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Hi Erik,
I do not think I want to add this field because it is not a very common thing that people need. If you would like to add this to your own block, you can do so by adding the following code to several of your block files:

In db.xml, just ABOVE the line containing '</table>', add this:
<field name="date_field" type="D"></field>


In controller.php, inside the 'save' function (just ABOVE the line containing 'parent::save($args);'), add this:
$args['date_field'] = Loader::helper('form/date_time')->translate('date_field', $args);


In edit.php, wherever you want the calendar control to appear, add this:
<div class="ccm-block-field-group">
   <h2>Date</h2>
   <?php echo echo Loader::helper('form/date_time')->date('date_field', $date_field); ?>
</div>


In view.php, wherever you want the date to be outputted, add this:
<?php echo date('F j, Y', strtotime($date_field)); ?>

(note that the 'F j, Y' above formats the date like 'January 1, 2011' -- see http://php.net/date for other formatting options)

Thanks for the feedback, and I hope this helps.

-Jordan
Erik74 replied on at Permalink Reply
Erik74
Thanks for a quick reply!

That worked like a charm.
It´s only 2 blocks I´m planning to add this to so it´s no problem to do it manually.
I just had to refresh the block from the dashbord to update the db after I made the edits to the files.

If someone else use this solution, EDIT.PHP have 2 echo, it should only be one.

change from:
In edit.php, wherever you want the calendar control to appear, add this:
<div class="ccm-block-field-group">
   <h2>Date</h2>
   <?php echo echo Loader::helper('form/date_time')->date('date_field', $date_field); ?>
</div>


to:
In edit.php, wherever you want the calendar control to appear, add this:
<div class="ccm-block-field-group">
   <h2>Date</h2>
   <?php echo Loader::helper('form/date_time')->date('date_field', $date_field); ?>
</div>

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.