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

I am trying to make an attachment system for the bottom of pages.

My first approach is attempting to use repeatable fields. It's not going to well. I have created a repeatable called 'attachments', and an editable field called 'attachment file'.

Code: Select all
<cms:repeatable name="attachments">
               <cms:editable type='file' name="attachment_file" allowed_ext='pdf, doc, docx, xls, xlsx' max_size='1024' />
            </cms:repeatable>
            <cms:show_repeatable "attachments" >


In the Couch Admin panel, it works as it is expected to work, and the repeatable fields come up, able to edit them and upload files, etc.

Using databound forms however, I have come to a standstill.

I have tried two things

First :
Code: Select all
<cms:input type='bound' name='attachments' trust_mode='1'/>

This results in the input field just like the Admin CP has being rendered. However, if I upload a file and save the document/edit, it does not get stored. I am sure this has to do with the input being bound to a repeatable which has no relation in the database for that function.
Code: Select all
<cms:input type='bound' name='attachment_file' trust_mode='1'/>

This results in a singular basic upload input, which does not work, either.

I have read through some other threads, and from some posts I've gathered that trying to use repeatable fields in a databound form does not work.

So, first question, Is there any way to make it work? This is my preferred approach.

Second :

I have read up a little but on relational fields : http://www.couchcms.com/docs/concepts/r ... ships.html

I am to the assumption that these relations are only bound to a cms page, or a root of a section.

What I'm thinking what might work is if I can bind a relationship of an attachment stored in an attachment page to a page_id. Is that possible? This way I can just list attachments where attachment k_page_id = document k_page_id. Is this possible?

Thanks for anyone with any comments or answers!
Try to start checking the permisions of the upload folder, it should at least try to upload the file even if isn't related to anything.
Apache logs should help you to find out if it's a permissions issue.

For the second part, if you have a main.php and a sub.php and you define the sub.php as just an attachment, you should be able to use the "has=one" relation to have multiple "single paged" uploads and then just call all the related attachments in the main.php using "reverse_related_pages".

If the attachments can't be on a repeatable field, then that should be your best shot for having multiple attachments for the same page.
LordNeo wrote: Try to start checking the permisions of the upload folder, it should at least try to upload the file even if isn't related to anything.
Apache logs should help you to find out if it's a permissions issue.

For the second part, if you have a main.php and a sub.php and you define the sub.php as just an attachment, you should be able to use the "has=one" relation to have multiple "single paged" uploads and then just call all the related attachments in the main.php using "reverse_related_pages".

If the attachments can't be on a repeatable field, then that should be your best shot for having multiple attachments for the same page.


The files upload fine in the AdminCP. CKEditor uploads without an issue there. The problem is that the only way to make it work with repeatables is to call the <cms:input type="bound" name="attachments"> which is the name of the repeatable region, not the name of the actual input field that is being repeated in the Admincp. If it is set to attachments, nothing is uploaded or even logged in the database. And I'm 100% sure that is because I can't use the repeatable region name for the bound input. When I used the input field, it uploads a file, but is not reflected in the database.

As you can see with the final result, it works fine from the Admincp, I just can't reflect any changes from my frontend databounds.
Image
Another issue I'm seeing with the relationals is that I'll need to use a seperate form element to submit them, as HTML doesn't support forms inside of forms to submit off one action without jquery, and i'd rather not go that direction.

So i guess I'm back to my question on the first approach, is there any way to use repeatable fields on a databound input?
Anything? Sorry for bumping the thread, just hoping someone has some insight on this.
@proofinlife,

While we can use repeatable-regions in databound forms, what we *cannot* use are the 'image' and 'file' types - the reason being that these two show the file-explorer and this is off-limits to anyone but the admins (too much of a security risk).

It is as an alternative to these two types that the type 'securefile' was introduced which is what you should use for the attachments (you may find this discussion useful - viewtopic.php?f=4&t=7830).

One limitation of 'securefile' is that it cannot be used as a repeatable region so we cannot give the ability to upload a variable number of attachments.

Usually a practical compromise can be found by providing a fixed number of securefile regions (e.g. five) and the user can choose to use any number from the maximum.

Hope it helps.
KK wrote: @proofinlife,

While we can use repeatable-regions in databound forms, what we *cannot* use are the 'image' and 'file' types - the reason being that these two show the file-explorer and this off-limits to anyone but the admins (too much of a security risk).

It is as an alternative to these two types that the type 'securefile' was introduced which is what you should use for the attachments (you may find this discussion useful - viewtopic.php?f=4&t=7830).

One limitation of 'securefile' is that it cannot be used as a repeatable region so we cannot give the ability to upload a variable number of attachments.

Usually a practical compromise can be found by providing a fixed number of securefile regions (e.g. five) and the user can choose to use any number from the maximum.

Hope it helps.


Yeah, that's what I've done so far with attachments. I made 5 total fields and noted that was the maximum per page. I don't see many reasons why there should be more for a simple sports committee site. Thanks KK :)
7 posts Page 1 of 1