Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
52 posts Page 2 of 6
Previous 1, 2, 3, 4, 5, 6 Next
Hi there
I tried the final code by KK but it did not work so I decided to start it from the beginning but <cms:show_repeatable 'my_repeatable' as_json='1' /> does not display anything. I don't know how to make the json work? I am using the 2.1.beta (20171223) version of Couch. Please help.
Did you update to latest version from Git? https://github.com/CouchCMS/CouchCMS/archive/master.zip
trendoman wrote: Did you update to latest version from Git? https://github.com/CouchCMS/CouchCMS/archive/master.zip

Thank you trendoman. It is displaying now.
But I am getting error "ERROR: Tag "form" - page_id required" while trying to display the form. Can you please help me.

I have created the template page service.php with repeatable field
Code: Select all
<cms:template title='Service' clonable='1' dynamic_folders='1' commentable='1'>
<cms:editable type='image' name='feat_img' label='Upload Features Image' width='600' show_preview='1' allowed_ext='jpg, jpeg, png' preview_width='80' order='1'/>
<cms:editable type='richtext' name='description' label='Description' desc="Enter description of service type listing here" toolbar='custom'
    custom_toolbar='bold, italic, underline, strike, -, subscript, superscript | format | justifyleft, justifycenter, justifyright, justifyblock | numberedlist, bulletedlist, -, outdent, indent, blockquote | undo, redo, removeformat | cut, copy, paste, pastetext, pastefromword | link, unlink, anchor | maximize, -, source' order='2' />
<cms:repeatable name='items' label='Service Information' desc="Information about the services" order='3' stacked_layout='1'>
<cms:editable type='text' name='service_name' label='Service Name' desc="Name of the service" />
<cms:editable type='richtext' name='service_desc' height='100' label='Service Description' desc="Description of the service" toolbar='custom'
    custom_toolbar='bold, italic, underline | format | justifyleft, justifycenter, justifyright, justifyblock | numberedlist, bulletedlist | cut, copy, paste, pastetext, pastefromword, - , removeformat | maximize, -, source'/>
<cms:editable name='service_type' label='Sevice Type' type='dropdown' opt_values="Make a selection=- | Free | Paid" required='1'/>
<cms:editable type='image' name='logo' label='Upload Logo' width='100' show_preview='1' allowed_ext='jpg, jpeg, png' preview_width='80'/>
<cms:editable type='image' name='screenshot' label='Upload Screenshot' width='600' show_preview='1' allowed_ext='jpg, jpeg, png' preview_width='80'/>
<cms:editable type='text' name='service_home' label='Home URL' desc="Service Homepage URL" />
<cms:editable type='text' name='service_signup' label='SignUp URL' desc="Service SignUp URL" />
<cms:editable type='text' name='service_features' label='Features URL' desc="Service Features URL" />
</cms:repeatable>
</cms:template>


and I created the snippet file

Code: Select all
            <div class="col-xl-12">
               <div class="card card-primary animated fadeInDown animation-delay-7">
                  <div class="card-header">
                   <h2 class="card-title"><i class="zmdi zmdi-comment-more"></i> Add Service to this post:</h2>
                  </div>
                 <div class="card-body">
            <cms:set submit_success="<cms:get_flash 'submit_success' />" />
                  <cms:if submit_success >
                     <div class="alert alert-success alert-dismissible" role="alert">
                        <p><strong><i class="zmdi zmdi-check"></i>Service Added!</strong> <br> Your addition awaits moderation and will be published as soon as reviewed by the Admin.</p>
                     </div>
                  </cms:if>
                  <cms:form masterpage='service.php' mode='edit' enctype='multipart/form-data' method='post' anchor='0'>
                  <cms:if k_success >
                     <cms:capture into='service_data' is_json='1'>
                        <cms:show_repeatable 'items' as_json='1' />
                     </cms:capture >
                     <cms:capture into='service_data.' is_json='1'>
                        {
                          "service_name" : <cms:escape_json><cms:show frm_service_name_fe /></cms:escape_json>,
                          "service_desc" : <cms:escape_json><cms:show frm_service_desc_fe /></cms:escape_json>,
                          "service_type" : <cms:escape_json><cms:show frm_service_type_fe /></cms:escape_json>,                     
                          "logo" : <cms:escape_json><cms:show frm_logo_fe /></cms:escape_json>,
                          "screenshot" : <cms:escape_json><cms:show frm_screenshot_fe /></cms:escape_json>,
                          "service_home" : <cms:escape_json><cms:show frm_service_home_fe /></cms:escape_json>,
                          "service_signup" : <cms:escape_json><cms:show frm_service_signup_fe /></cms:escape_json>,
                          "service_features" : <cms:escape_json><cms:show frm_service_features_fe /></cms:escape_json>
                        }
                     </cms:capture >
                     <cms:db_persist_form
                        _invalidate_cache='0'
                        items=service_data
                     />
                     <cms:if k_success >
                        <cms:set_flash name='submit_success' value='1' />
                        <cms:redirect k_page_link />
                     </cms:if>
                  </cms:if>
                  <cms:if k_error >
                     <div class="alert alert-danger alert-dismissible" role="alert">
                        <p><strong><i class="zmdi zmdi-close-circle"></i>Could not add service!</strong> <br> The following error occured while processing your post:</p>
                        <cms:each k_error >
                           <br><cms:show item />
                        </cms:each>
                     </div>
                  </cms:if>
                    <fieldset class="container">
                     <div class="form-group row">
                       <label for="ServiceName" autocomplete="false" class="col-lg-2 control-label">Service Name</label>
                       <div class="col-lg-4">
                        <cms:input type='text' name='service_name_fe' size="22"  tabindex="1" required="1" class="form-control" id="ServiceName" placeholder="Service Name(Required)"/>
                       </div>
                       <label for="ServiceType" autocomplete="false" class="col-lg-2 control-label">Service Type</label>
                       <div class="col-lg-4">
                        <cms:input type='dropdown' name='service_type_fe' size="22" tabindex="2" required="1" class="form-control" id="ServiceType" opt_values="Make a selection=- | Free | Paid" />
                        </div>
                     </div>
                     <div class="form-group row">
                       <label for="Description" class="col-lg-2 control-label">Description</label>
                       <div class="col-lg-10">
                        <cms:input type='textarea' name='service_desc_fe' class="form-control" rows="4" id="Description" placeholder="Description of the service...(Required)" tabindex="3" validator_msg="required=Please enter something as comment" required="1" />
                       </div>
                     </div>
                     <div class="form-group row">
                       <label for="Logo" class="col-lg-2 control-label">Logo</label>
                       <div class="col-lg-10">
                        <cms:input type='image' name='logo_fe' width="100" allowed_ext='jpg, jpeg, png' tabindex="4" required="1" class="form-control" id="Logo" placeholder="Logo(Required)" />
                       </div>
                     </div>
                     <div class="form-group row">
                       <label for="Screenshot" class="col-lg-2 control-label">Screenshot</label>
                       <div class="col-lg-10">
                        <cms:input type='image' name='screenshot_fe' width="100" allowed_ext="jpg, jpeg, png" tabindex="5" required="1" class="form-control" id="Screenshot" placeholder="Screenshot(Required)" />
                       </div>
                     </div>
                     <div class="form-group row">
                       <label for="HomeURL" class="col-lg-2 control-label">Home URL</label>
                       <div class="col-lg-10">
                        <cms:input type='text' name='service_home_fe' tabindex="6" required="1" class="form-control" id="HomeURL" placeholder="Homepage URL(Required)" />
                       </div>
                     </div>
                     <div class="form-group row">
                       <label for="SignUpURL" class="col-lg-2 control-label">SignUp URL</label>
                       <div class="col-lg-10">
                        <cms:input type='text' name='service_signup_fe' tabindex="6" required="1" class="form-control" id="SignUpURL" placeholder="Homepage URL(Required)" />
                       </div>
                     </div>
                     <div class="form-group row">
                       <label for="FeaturesURL" class="col-lg-2 control-label">Features URL</label>
                       <div class="col-lg-10">
                        <cms:input type='text' name='service_features_fe' tabindex="6" required="1" class="form-control" id="FeaturesURL" placeholder="Homepage URL(Required)" />
                       </div>
                     </div>
                     <div class="form-group row justify-content-end">-->
                     <!--<div class="col-lg-6">
                     <cms:if k_logged_out >
                        Recaptcha script here
                     </cms:if>
                     </div>-->
                       <div class="col-lg-6 my-auto">
                        <cms:input type="submit" value="Submit" name="submit" class="btn btn-raised btn-primary float-right"/>
                       </div>
                     </div>
                    </fieldset>
                 </cms:form>
               </div>
               </div>
            </div>


What have I done wrong here?
Since you want to save something to service.php template, the form needs to know which page you are going to edit. Template is clonable and is expected to have several cloned pages. Note that in KK's example he used non-clonable template, which explains your copy-pasting mistake.

One of possible code solutions is to use this form on page-view and therefore use current page id in the form's parameter "page_id":
<cms:form masterpage='service.php' mode='edit' page_id=k_page_id enctype='multipart/form-data' method='post' anchor='0'>


Code: Select all
<cms:if k_is_page >
    <div class="col-xl-12">
       ....
    </div>
</cms:if>
trendoman wrote: Since you want to save something to service.php template, the form needs to know which page you are going to edit. Template is clonable and is expected to have several cloned pages. Note that in KK's example he used non-clonable template, which explains your copy-pasting mistake.

One of possible code solutions is to use this form on page-view and therefore use current page id in the form's parameter "page_id":
<cms:form masterpage='service.php' mode='edit' page_id=k_page_id enctype='multipart/form-data' method='post' anchor='0'>


Code: Select all
<cms:if k_is_page >
    <div class="col-xl-12">
       ....
    </div>
</cms:if>


Thank you trendoman.

But I think something is wrong with my code because I am getting another error message.
ERROR: Tag "input" has unknown type "image" :?:
How to make it work?
According to docs, "image" is invalid type for cms:input.. http://couchdocs/tags-reference/input.html
Solution is posted in such threads (among many) as in viewtopic.php?f=2&t=10016#p23416 and viewtopic.php?f=4&t=8414#p15642
@upadesh,
From the description of the editable regions you have defined, it appears you are creating something akin to a 'Classifieds' section.

If that is correct, I don't think using repeatable-regions to hold that kind of data would be practical -
1. since all the rows are saved in the same page there has to be a limit to the data you can store in there
2. type 'securefile' region (which is the only way to allow visitors to upload images/files) doesn't work as repeatable.

So, I suggest you please switch over to the conventional method of using a clonable template and then persisting each DBF submission as as separate cloned page.

Hope this helps.
Hi all, I've been having a few problems implementing this in a site, I thought I'd ask a couple of quick questions before I try and get real help.
1: I'm using Couch 2.1 - I think the current release version should support this?
2: without posting loads of code, this is what I am trying to do.

I have a clonable template (jobs.php), with a repeatable (job_tasks). Tasks are created in a separate clonable template (tasks.php) which has dynamic folders. As relations won't work in repeatable regions (as far as I am aware), there is a dynamic dropdown (populated with the task k_page_name) in the jobs repeatable region to choose the tasks.

The point of doing this is so that the user can go to a job with no tasks (on the front end), click a check box generated from the task folder names, and all the tasks in that folder will be added to the job.
My question is - do you (anyone!) think that the dynamic dropdown is stopping this from working? The JSON I am generating is valid, and it seems to add repeatables when the form is submitted, but the dropdown task name is not changing. The JSON uses k_page_name from tasks.php, the same as the dynamic dropdown.

I can post code if required, but thought I would ask these questions first!
Thanks,
ewanmc
@ewanmc, I think taking a look at your code would be helpful.
If possible, please redact it to post only the relevant portions.

Thanks,
OK, thanks KK, I'll give it a go. (I should mention that I have successfully used your technique in another site, but it is defeating me on this occasion.)

Templates
Code: Select all
<cms:template title='Jobs' clonable="1">
<cms:repeatable name='job_tasks'>
        <cms:editable name="job_task" label="Which task?" type="dropdown" opt_values='tasklist.php' dynamic='opt_values'/>
        <cms:editable name="job_task_status" label="Task Status" type="dropdown" opt_values='incomplete | completed'/>
        <cms:editable name="job_task_completed" label="Date completed" type="datetime"/>
        <cms:editable name="job_task_notes" label="Task Notes" type="nicedit" />
    </cms:repeatable>
</cms:template>

<cms:template title='Tasks' clonable="1" dynamic_folders="1" folder_masterpage='taskfolders.php'>
</cms:template>

tasklist.php
<cms:pages masterpage="tasks.php">
    <cms:show k_page_name /> |
</cms:pages>


So here's the tricky stuff: (this code appears if k_is_page on jobs.php)
Code: Select all
<input type="checkbox" name="alltask" id="select_all" value="all">All<br/>
                <cms:folders masterpage="tasks.php">
                <input type="checkbox" name="task" value="<cms:show k_folder_name />" class="checker"><cms:show k_folder_title /><br/>
               
                </cms:folders>
                <cms:form
        masterpage=k_template_name
        page_id=k_page_id
        mode='edit'
        enctype='multipart/form-data'
        method='post'
        anchor='0'
        >
                <cms:if k_success>
                    <cms:capture into='my_data' is_json='1'>
                   <cms:show_repeatable 'job_tasks' as_json='1' />
                   </cms:capture >
               <cms:set taskget="<cms:gpc 'checkitout'/>" scope="global"/>
                    <cms:set tas_count="0" scope="global"/>
                 
      <cms:each taskget sep=',' >
                    <cms:set fget="<cms:show item />" scope="global"/>
                       <cms:folders masterpage="tasks.php">
                        <cms:if k_folder_name="<cms:show fget />">
                          <cms:pages masterpage="tasks.php" folder=k_folder_title>
                                <cms:set tas_count="<cms:add tas_count '1'/>" scope="global"/>
                          </cms:pages>
                        </cms:if>
                    </cms:folders>
             
                </cms:each>
                       
                <div>Totaltasks: <cms:show tas_count />    </div>
                   
                <cms:set ta_count="0" scope="global"/>   
                <cms:capture into='my_data.' is_json='1'>
               [<cms:each taskget sep=',' >
                    <cms:set fget="<cms:show item />" scope="global"/>
                       <cms:folders masterpage="tasks.php">
                        <cms:if k_folder_name="<cms:show fget />">
                             <cms:pages masterpage="tasks.php" folder=k_folder_title>
                                <cms:set ta_count="<cms:add ta_count '1'/>" scope="global"/>
                                {
                  "job_task" : <cms:escape_json><cms:show k_page_name /></cms:escape_json>,
                  "job_task_status" : <cms:escape_json>incomplete</cms:escape_json>,
                  "job_task_completed" : <cms:escape_json>0000-00-00</cms:escape_json>,
                  "job_task_notes" : <cms:escape_json>test</cms:escape_json>
                 
               }<cms:if ta_count lt "<cms:show tas_count />">,</cms:if>
                            </cms:pages>
                        </cms:if>
                    </cms:folders>
             
                </cms:each>]
                                </cms:capture>
                 
   
                    <cms:show my_data as_json="1" />
                   
                        <cms:db_persist_form
                _invalidate_cache='0'
                job_tasks=my_data
            />

            <cms:if k_success >
                <cms:set_flash name='submit_success' value='1' />
                <cms:redirect k_page_link />
            </cms:if>

   
                <cms:if k_error><div><cms:show k_error /></div></cms:if>
                <cms:input type="text" name="checkitout" id="checkitout"/>
                <cms:input type="submit" name="submit" value="Add these tasks"/>
                </cms:form>
           
               
               </div>


So when I show my_data (line 58) it displays as valid json, but I'm obviously missing something about adding repeatables. Possibly something daft, might even help to have someone else look at it. I had been leaving job_task_completed and _notes blank, but it hasn't made a difference adding values. (Unless the 0000-00-00 is invalid?)

I've missed out the javascript - it takes the checker checkboxes and creates a comma-separated list of their values, and populates the "#checkitout" value. This works fine, the data is getting through. It's just not creating the new repeatable.
In fact, I might as well add it.
Code: Select all
<script>
            $("#select_all").change(function(){
    $(".checker").prop('checked', $(this).prop("checked"));
                 var favorite = [];
            $.each($("input[name='task']:checked"), function(){           
                favorite.push($(this).val());
            });
$("#checkitout").val(favorite.join(","));
});

$('.checker').change(function(){
    var favorite = [];
    if(false == $(this).prop("checked")){
        $("#select_all").prop('checked', false);
    }
    if ($('.checker:checked').length == $('.checker').length ){
        $("#select_all").prop('checked', true);
    }
$.each($("input[name='task']:checked"), function(){           
                favorite.push($(this).val());
            });
$("#checkitout").val(favorite.join(","));   
});
</script>


Thanks for your help KK!
Previous 1, 2, 3, 4, 5, 6 Next
52 posts Page 2 of 6
cron