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

I'm trying to implement on my site a Databound Forms, but did not understand how can I make my visitor send a picture through the DataBund.

And it's possible that he select the folder where the page is created?

Thank you,

Rafael
Hi Rafael,

..but did not understand how can I make my visitor send a picture through the DataBund.
The example used in the documentation (http://www.couchcms.com/docs/concepts/d ... forms.html) allows the visitors to upload text files as resumes (using an editable region of type 'securefile'). We can easily adapt it to allow uploading only image files -
Code: Select all
<cms:editable name='uploaded_image' required='1' allowed_ext='jpg, jpeg, png, gif' max_size='2048' type='securefile' />


And it's possible that he select the folder where the page is created?
Sure. Use the following in your form (we are binding with the system field 'k_page_folder_id' that shows the folders in a dropdown)
Code: Select all
<cms:input name="k_page_folder_id" type="bound" />

Hope this helps
Hi KK,

I had tried this way, but then I can't display the image on the page with the command <cms:show imagefile />

And the folder selection can be preset as well?

Thank you
Hi Rafael,

Sorry for the delay in my reply :)

Coming to the problems you mentioned -
I can't display the image on the page with the command <cms:show imagefile />
There is more information pertaining to the uploaded file/image then just its name. So, we have a dedicated tag named 'show_securefile' for getting this info. Please try the following -
Code: Select all
<cms:show_securefile 'name_of_your_securefile_region_here' >
    <cms:dump />
</cms:show_securefile>

It'll output something like this -
* show_securefile
o file_id: 53
o file_name: img01.jpg
o file_ext: jpg
o file_is_image: 1
o file_size: 18725

You'll notice that the variables made available still do not show us the path of where the image is stored. That is deliberate and is the very point of the 'secure' in securefile - no outsider should be able to know where the uploaded images get stored and what they are named physically.

Sometimes that is fine because we just want the visitors to upload files and not to access them back (like in our sample 'application submission').
However, there are times when we do need to make the uploads available on the front-end - e.g. displaying the uploaded images on the site or making the uploaded files available for download.

For such cases, we do the following -
Code: Select all
<cms:show_securefile 'name_of_your_securefile_region_here' >
    <cms:if file_is_image >
        <a href="<cms:cloak_url link=file_id />"><img src="<cms:cloak_url link=file_id thumbnail='1' />" /></a><br />
        <cms:show file_name /> (<cms:size_format file_size />)
    <cms:else />
        <a href="<cms:cloak_url link=file_id />"><cms:show file_name /></a> (<cms:size_format file_size />)
    </cms:if>
</cms:show_securefile>

Please notice how we are feeding the info gathered from cms:show_securefile tag into cms:cloak_url tag (a very old feature of Couch - http://www.couchcms.com/docs/concepts/c ... links.html).

Let us come to your second problem -
the folder selection can be preset as well?
Certainly. Since you want to use a 'preset' value for the folders, we won't display the folder editable region as a bound field on the form.
Instead, we'll silently 'inject' the folder id into all successful submissions like this -
<cms:if k_success >

..

<cms:db_persist_form
_invalidate_cache='0'
_auto_title='1'
k_page_folder_id='71'
/>

Of course, we need to know the 'id' of the folder. You can take a look at the folders dropdown (chrome developer tools, firebug or view-source) to find that.

Hope this helps.
Do let us know.

Thanks.
Hello again KK,

I am who need to say sorry for the delay in my reply.

Unfortunately the first code hasn’t worked yet, it is intermittent, sometimes works and sometimes doesn’t. But I’m still hopeful. Being more specific, this part of the code hasn’t worked:

Code: Select all
<cms:cloak_url link=file_id thumbnail='1' />


But this one has… in some cases:

Code: Select all
<cms:cloak_url link=file_id />


Besides this, the second code works very well. I’ll get in touch if the situation changes here.

I’m attaching the page’s links and codes here too.

Code: Select all
<cms:editable name='imagefile' allowed_ext='png, jpg, jpeg' max_size='2048' type='securefile' />

Code: Select all
<cms:show_securefile 'imagefile' >
    <cms:if file_is_image >
   <a href="<cms:cloak_url link=file_id />" rel="prettyPhoto">
      <img src="<cms:cloak_url link=file_id  />" />
   </a>
    </cms:if>
</cms:show_securefile>


http://revistafarofino.com.br/reviralata/

I appreciate your help and attention.

Have a nice week.
Regards.
I'd be interested in getting an answer to this as well. Using the code above with (cloak_url) I get the URL to a download of the image file, which doesn't appear to work with the <img> tag.

It end's up yielding something like the code below.

Code: Select all
<img src="http://localhost:8888/sci/couch/download.php?auth=1%7C1%7C0%7C0%7C0%7C0%7C634621d4db4ce3828253add65e8cb0bb">
OK, I admit friends, the documentation on securefile is rather scant at this point.
I'll try and put down all the pertinent info about it here (including how it deals with thumbnails).

As you know, securefile can be used to upload both files as well as images.
So, in a sense, it is a combo of the regular 'file' and 'image' type editable regions.

Optionally, we can also configure it to create thumbnails for uploaded images (which is what you are interested in). So, now it actually becomes a combo of file, image and thumbnail type editable regions rolled into one.

So, the securefile region actually supports a whole lot of parameters that are common to the regular regions it acts as.
Depending on whether the uploaded entity is a file or an image, the relevant parameters come into play.

Let us take a look at the parameters that can be used to handle uploaded images.
When the uploaded entity is an image, all the usual parameters of the regular 'image' editable region come into effect.
Namely -
* width
* height
* enforce_max
* crop
* quality
* show_preview
* preview_width
* preview_height

You can take a look at the docs for 'image' type for details - (http://www.couchcms.com/docs/tags-refer ... image.html).

And now the info you were looking for:
To make securefile also act as a thumbnail region, we have to set at least one of the following two parameters -
* thumb_width
* thumb_height

Those are the parameters that signal securefile to create the thumbnail.

Following parameters can be used to exert finer control over the thumbnail created
* thumb_enforce_max
* thumb_quality

Additionally, if we have set the 'show_preview' parameter mentioned above, we can make securefile use the thumbnail (instead of the main image) to show in the preview. Following parameter does it -
* use_thumb_for_preview

As an example of usage of the parameters, we'll use the original definition of Rafael
Code: Select all
<cms:editable 
    name='imagefile'
    allowed_ext='png, jpg, jpeg'
    max_size='2048'
    type='securefile'
/>

We'll modify it as follows to make securefile create a thumbnail of width 100px and also show it as preview -
Code: Select all
<cms:editable 
    name='imagefile'
    allowed_ext='png, jpg, jpeg'
    max_size='2048'
    type='securefile'
   
    thumb_width='100'
    show_preview='1'
    use_thumb_for_preview='1'
/>

Hope this helps.
Do let us know.
Now the code worked worked,

thank you
Thank you, KK.

Works perfectly!
You are welcome, gentlemen :)
19 posts Page 1 of 2