Problems, need help? Have a tip or advice? Post it here.
13 posts Page 2 of 2
KK wrote:
My problem is that I should be able to edit the saved publish date also from the front-end, ideally using datepicker or if this isn't possible, other way. What do you think about this, is it possible?
Not a problem. Just set the default_time of the 'datetime' region to the publish_date of the page being edited and that would be it.

Sample code -
Code: Select all
<cms:set my_form_mode='edit' />

<cms:input
    name='my_datetime'
    type='datetime'
    default_time="<cms:if my_form_mode='edit' && k_page_date!='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else />@current</cms:if>"
    required='1'
/> 

In the code above we are setting the default_time to the page's publish date only if the page is being 'edited' (as opposed to being 'created') and is not in an 'unpublished' state.

In you happen to be using Couch v2.0, the documentation at viewtopic.php?f=5&t=10241 has a full-fledged example where we use a custom-field to mimic the system publish field. I suggest you take a look at how it works.

Hope it helps.


Thank you KK for the quick reply. I'm using this code:
Code: Select all
<cms:form 
        masterpage='members/folders.php'
        mode='edit'
        page_id=my_page_id
        enctype="multipart/form-data"
        method='post'
        anchor='0'
        >
       
        <cms:if k_success >
            <cms:db_persist_form
            k_publish_date=frm_my_datetime
            />
        </cms:if>
       
        Date*<br />
        <cms:input name='my_datetime' type='datetime' default_time="<cms:show k_page_date />" required='1' /><br />   
        <button type="submit"><i class="fa fa-floppy-o" aria-hidden="true"></i>Save</button>

</cms:form>
and all I get displayed for each page date I'm trying to edit is Jul 01 2016 Why?
Thank you.
The code seems to be working just fine for me (on v2.0).
Please use <cms:show k_page_date /> on each page being edited to see what the actual date is.
KK wrote: The code seems to be working just fine for me (on v2.0).
Please use <cms:show k_page_date /> on each page being edited to see what the actual date is.

Hm... strange. Placing <cms:show k_page_date /> elsewhere in the form also displays 2016-07-01 ....
EDIT: There may be a logic of this, because I'm using edit-folder.php (created on 1st July 2016!) for editing pages from folders.php. But then how is possible that all other informations from the form are correct and only k_page_date is incorrect?
Somewhere on the top of the page I was already displaying info's such as folder name, creation date, author, folder description this way:
Code: Select all
<cms:set my_page_id="<cms:gpc method='get' var='id' />"/>
      
       <cms:pages masterpage='members/folders.php' id=my_page_id >
        <h1><cms:show foldername /></h1>
        <h2><span>Date:</span> <cms:date k_page_date format='d.m.Y' /> <span>Author:</span> <cms:show author /> <span>Description:</span> <cms:show folderdescription />
       </cms:pages>
so I implemented this masterpage thing in my form
Code: Select all
<cms:pages masterpage='members/folders.php' id=my_page_id >
           Date*<br />
           <cms:input name='my_datetime' type='datetime' default_time="<cms:show k_page_date />" required='1' /><br />
</cms:pages>
and now things are working :) The only thing is I can't imagine why masterpage should be used in the form in order to display the correct date, since all other same page related informations in the form are correct.
By the way: I'm using Couch CMS version 1.4.5RC2.
13 posts Page 2 of 2