Problems, need help? Have a tip or advice? Post it here.
11 posts Page 1 of 2
Hi All,

New user here, loving Couch, but can't seem to figure out how to create a template where I can add/delete a pdf from a page of pdfs all uploaded using couch. What I want is a page that shows pdfs with a title and a date that I input in a template when uploading the file and a link from the title to the pdf doc.

So the page would look like this:

First Grade


Second Grade


I believe I would have to create a clonable template and each pdf would be its own page (similiar to blog maybe). But i'm having a hard time figuring out how to do this then display them all on one page.

any help would be greatly appreciated!
Hello and welcome, shuff19 :)

You are right about using cloned pages to represent each PDF entry.
Another approach could be using repeatable regions (http://www.couchcms.com/docs/concepts/r ... gions.html).

If you go with the cloned pages approach, listing PDFs is no different to listing any other editable regions. For example, the following code lists the titles of all pages belonging to 'whatever-template-name.php' template (put your template's name here)
Code: Select all
<cms:pages masterpage='whatever-template-name.php' >
     <cms:show k_page_title /><br />
</cms:pages>

Assuming your template has an editable regions of type 'file' and name 'my_pdf', the above code can be slightly altered to link the page-names to the pdfs
Code: Select all
<cms:pages masterpage='whatever-template-name.php' >
     <a href="<cms:show my_pdf />"><cms:show k_page_title /></a><br />
</cms:pages>

Similarly you can show the date as well.

Hope this helps.
KK,

Thanks for the help i appreciate it! I actually decided to go with a bound form to enable the user to upload a new pdf and add a title and date of the event. That is all working well, however instead of editable region type "file" I used "securefile" and can not get it to show on the page I am using to display the data. Below is what I have used.

Code: Select all
<cms:template title='E-friday Form' clonable='1' order='12'>
    <cms:editable name='date' required='1' type='text' />
    <cms:editable name='position' required='1' type='dropdown'
        opt_values=' Please choose=- | Elementary School | Upper Elementary | Middle School | High School | Multiple Schools | YMCA | Adults'
    />
    <cms:editable name='pdfdoc' required='1' allowed_ext='pdf' type='securefile' />
</cms:template>


and then the form data
Code: Select all
<cms:form 
            masterpage=k_template_name
            mode='create'
            enctype='multipart/form-data'
            method='post'
            anchor='0'
            >
           
            <cms:if k_success >
           
                <cms:check_spam email=frm_email />
               
                <cms:db_persist_form
                    _invalidate_cache='0'
                    _auto_title='1'
                />
               
                <cms:if k_success >

    <cms:db_persist_form
        _invalidate_cache='0'
        _auto_title='0'
    />           

    <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"><strong>Error:</strong>
                    <cms:each k_error >
                        <br><cms:show item />
                    </cms:each>
                </div>
            </cms:if>
           
         
         <div class="form-group <cms:if k_error_title >has-error</cms:if>">
            <label class="control-label" for="title">Title<span class="required">*</span></label>
            <cms:input class="form-control" id="title" name="k_page_title" type="bound" />
         </div>
         <div class="form-group <cms:if k_error_date >has-error</cms:if>">
            <label class="control-label" for="date">Date</label>
            <cms:input class="form-control" id="date" name="date" type="bound" value="" />
         </div>
         <div class="form-group <cms:if k_error_position >has-error</cms:if>">
            <label class="control-label" for="position">What Section should this be posted under? <span class="required">*</span></label>
            <cms:input class="form-control" id="position" name="position" type="bound" />   
         </div>
         <div class="form-group <cms:if k_error_pdfdoc >has-error</cms:if>">
            <label class="control-label" for="pdfdoc">Upload the PDF<span class="required">*</span></label>
            <cms:input class="form-control" id="pdfdoc" name="pdfdoc" type="bound" />
            <p class="help-block">PDF Documents Only</p>
         </div>
            <div class="form-group <cms:if k_error_human >has-error</cms:if>">
            <label class="control-label" for="human">What colour is a blue apple? (4 characters required)</label>
            <cms:input class="form-control" id="human" name="human" type="text" required='1' validator='regex=/^blue$/i' />
         </div>
           
            <cms:if "<cms:not submit_success />" >
                <button class="btn btn-primary" type="submit">Create Entry</button>
            </cms:if>
           
      </cms:form>


The Form works correctly uploads the record with the pdf and all is well, but then to display this I used:
Code: Select all
 <cms:pages masterpage='efriday.php' >
     <a href="<cms:show_securefile 'pdfdoc' />"><cms:show k_page_title /></a> - <cms:show date /><br />
</cms:pages>


This displays the title, date and makes the title a hyperlink, but the hyperlink is not correct. it shows as pointing to itself (the page that it is displaying on) any idea where I might be going wrong here?
Hi,

The cms:show_securefile tag won't work as a self-closing tag - you need to use it as follows -
Code: Select all
<cms:pages masterpage='efriday.php' >
    <cms:show_securefile 'pdfdoc' >
        <a href="<cms:cloak_url link=file_id />"><cms:show file_name /></a> (<cms:size_format file_size />)
    </cms:show_securefile>
</cms:pages>

Hope this helps.

P.S. I noticed that the code you posted is using cms:db_persist_form tag twice. Please remove the second instance.
kk

Thanks for the quick response, however now using the code you provided, nothing shows on the page at all. Everything within the show-securefile tags is not showing up.

Code: Select all
<cms:pages masterpage='efriday.php' >
      <cms:show_securefile 'pdfdoc' >
        <a href="<cms:cloak_url link=file_id />"><cms:show k_page_title /></a> - <cms:show date /><br />
    </cms:show_securefile>
</cms:pages>


any thoughts?
Strange. Try debugging by placing a cms:dump in there.
Code: Select all
<cms:pages masterpage='efriday.php' >
    <cms:show_securefile 'pdfdoc' >
        <cms:dump />
    </cms:show_securefile>
</cms:pages>

What do you get?
Adding to my last reply -
there is also a reported bug with using secure_file with cms:pages loop.
Please also try patching it - viewtopic.php?p=14893#p14893
KK,

It was indeed the bug. Replacing page.php did the trick!

Thanks a million!
KK,

Almost there, I now have a display form that displays the pdf files with title and link to the pdf doc along with the date. But I am having a small issue still.

1. I am showing the files on the page by position (this is picked when creating the entry) and sorted by the custom date field which is the date of the event. The problem is instead of sorting by actual date, it sorts using the date field but sorts ascending by alpha. See below example.

(I understand why, the input field for date is just a text field)

First Grade

Hats for the homeless - November 4
Museum Field Trip Permission Slip - October 10
Museum Field Trip Flyer - October 11

Second Grade

Bake Sale Order Form - October 5
Agenda for Assembly - October 7

I think what I need to do is set the publish_date as the event date from the front end form instead of using a custom field called date, then do this to display

Code: Select all
<cms:pages masterpage='efriday.php' custom_field='position==First Grade' orderby='publish_date' order='desc'></cms:pages>


Can I set a publish_date from the front end with an input?
A text field can be used for date, if required, and it'll sort exactly as the system publish-date does - it only requires enforcing the date inputted to be of a particular format. You can find details in the following post - viewtopic.php?f=8&t=7126

If you wish to set the publish-date from front-end, it can be done like this
Code: Select all
<cms:db_persist_form 
    k_publish_date = '0000-00-00 00:00:00'
/>
- where the date should be in the format mentioned before.

Hope this helps.
11 posts Page 1 of 2
cron