Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hello...

I have developed an event system using CouchCMS and am currently building out some entries for the calendar. However, rather than using the native "Publish Date" as the input field for each event date, I have used a <cms:editable> field called "event_date" with a type of "datetime". I prefer not to use "Publish Date" for a variety of reasons.

Here are the parameters I am collecting for this "event_date" field:

Code: Select all
<cms:editable
      name='event_date'
      label='Event Date'
      desc='Enter the day and time of the event in Eastern Standard Time'
      type='datetime'
      format='Y-m-d H:i'
      allow_time='1'
      am_pm='1'
      required='1'
   />


Therefore, now that I am implementing the "Event Calendar" shown in the CouchCMS documentation, I would like the query for each day to be based on the "event_date" custom field rather than the native "Publish Date" as it is currently set up. Below is the code for my calendar thus far:

Code: Select all
<cms:calendar date="<cms:gpc 'cal' />" masterpage=k_template_name show_future_entries='1' >
               <div class="h2">
                  <a href="<cms:concat k_page_link '?cal=' k_prev_calendar_date />"> << </a>
                  <cms:date k_calendar_date format='F Y' /></th>
                  <a href="<cms:concat k_page_link '?cal=' k_next_calendar_date />"> >> </a>
               </div>
               <table class="calendar_big">
                  <tr>
                     <cms:repeat count='7'>
                     <td class="months_heading"><cms:zebra 'Su' 'M' 'T' 'W' 'Th' 'F' 'S'/></td>
                     </cms:repeat>
                  </tr>

                  <cms:weeks>
                     <tr>
                     <cms:days >
                        <cms:if k_timeline_position='present'>
                           <cms:set tdclass='today' />
                        <cms:else />
                           <cms:set tdclass='' />
                        </cms:if>

                        <cms:if k_position='current_month' >
                           <cms:if k_count_entries >
                              <td class='entries <cms:show tdclass />' align='center'>
                                 <cms:show k_day />
                                 <ul>
                                 <cms:entries limit='2'>
                                    <li style="margin-bottom: 3px;">
                                       <a href="https://www.cvent.com/d/<cms:show cventcode />"><cms:show event_title /></a>
                                    </li>
                                 </cms:entries>
                                 </ul>
                              </td>
                           <cms:else />
                              <td class='<cms:show tdclass />' ><cms:show k_day /></td>
                           </cms:if>
                        <cms:else />
                           <td class='other_month'><cms:show k_day /></td>
                        </cms:if>
                     </cms:days>
                     </tr>
                  </cms:weeks>
               </table>
            </cms:calendar>



How can I modify this code to use the "event_date" editable field rather than the "publish date"?

Would appreciate any help. Thanks.
Hi,

I think you should find the following post useful -
viewtopic.php?f=4&t=11234#p29528

The crux of the matter is that the calendar works only with the publish_date; so, you'll need to "sync" your custom field with the publish date (i.e. the two always contain the same date).

Hope this helps.
I previously tried that solution but I am still getting the same error.

Here is my template now:

Code: Select all
<cms:template title='Event Calendar' clonable='1'>

   <cms:editable name='event_title' label='Event Title' desc='Enter a title for this event—different from the post title, which must be unique' type='text' required='1' />
   
   <cms:editable
      name='start_date' label='Start Date' type='datetime' allow_time='1' am_pm='1'
      required='1'
      validator='MyEvent::start_date'
      validator_msg='myevent::start_date=Incorrect date format'
   />
   
   <cms:editable name='cventcode' label='Cvent Code' desc='If this is a Cvent event, enter the code which comes after /d/ in the link' type='text' />
   <cms:editable name='event_location' label='Event Location' desc='Enter the location as City, State—i.e. Orlando, FL—or Webinar' type='text' required='1' />
   <cms:editable name='event_faculty' label='Event Faculty' desc='Enter the faculty name if known, otherwise leave it blank' type='text' />
   <cms:editable name='event_description' label='Event Description' desc='Enter any needed comments or details, otherwise leave it blank' type='richtext' />
   <cms:editable name='event_registrationdate' label='Registration Date' desc='Enter when the user needs to register by for this event' type='datetime' format='Y-m-d' order="10" />

   
   <cms:folder name='courses' title='Hands-On Bioskills Courses' />
   <cms:folder name='webinars' title='Peer-to-Peer Webinars' />
   <cms:folder name='otherevent' title='Other Type of Event' />
   


</cms:template>



and here is my kfunctions.php file now (the top level file, not the one in the "addons" folder):

Code: Select all
<?php

   // All-Purpose Embed Shortcode
   // Embed any code (almost).
   // Careful of your quotation mark types.
   // Won't accept the word "script."  No new lines. PHP code won't work.
   // Usage: [embed code='<p>Any code goes here.</p>']
   $FUNCS->register_shortcode( 'embed', 'embed_handler' );
   function embed_handler( $params, $content=null ){
      global $FUNCS;

      extract( $FUNCS->get_named_vars(array(
         'code' => '',
      ), $params) );

       // Pass on the code to Couch for execution using the 'embed' function
      return $FUNCS->embed( $code, $is_code=1 );
   }

class MyEvent{
    function start_date( $field ){
        global $FUNCS;
       
        $start_date = trim($field->get_data());
        if( !preg_match('/(?:19|20)\d\d-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/', $start_date ) ){
            return KFuncs::raise_error( "Incorrect date format" );
        }
       
        // Set publish_date to value of this field
        $f = &$field->siblings[3];
        $publish_date = trim( $f->get_data() );
        if( $publish_date != '0000-00-00 00:00:00' ){
            $start_date = $FUNCS->make_date( $start_date );
            if( $publish_date != $start_date ){
                $f->store_posted_changes( $start_date );
            }
        }
        unset( $f );
       
        return true;
    }
}
   
?>



When I try to put in an entry in the admin template, after refreshing the template file, I receive the error shown in the attached screenshot.

Screen Shot 2021-02-12 at 10.21.31 AM.png
Screen Shot 2021-02-12 at 10.21.31 AM.png (100.43 KiB) Viewed 971 times



What am I missing?

Any help would be appreciated.
The error suggests that the function was not found. I don't see any problem in keeping it in the kfunctions.php file of your site root but you can try moving it to the one that exists in couch/addons folder and see if that helps.

That said, the screenshot you posted makes me believe that the only reason you are using a 'shadow' editable region, instead of the system publish_date field, is the default location of the latter.

If that is correct, then you can easily change the location of the system field itself and make it appear in the main form (which would save you from having to use a second field).

It that interests you, please see the 'Customizing the Form screen' section of the following post -
viewtopic.php?f=5&t=10241

Hope this helps.
Adding the PHP code to the kfunctions file in the addons folder did the trick.

Thanks very very much for your help.
You are welcome :)
6 posts Page 1 of 1