Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
20 posts Page 1 of 2
Hi there, here I am, the biggest pain in the **s of the forum.....I desperately need a help as I'm doing a huge contact form and I'm using the cause method with no php :) awesoommmeee!!!

I arrive at the end and the client need a file upload ...just a stupid CV....I read it's no there a patch?? please guys help me....


Hi Emanuale,

As you mentioned, attachments are not currently supported by cms:form (as well as the cms:send_mail tag).

I have, however, created an extension for you that tries to add the missing functionality.
These are the two steps you need to carry out to get the extension working (will require at least Couch v1.2)-
1. Download the attached 'emailex.php' (unzip it first) and place it within your couch installation folder.
(7.78 KiB) Downloaded 426 times

2. Edit (or create a file named) 'kfunctions.php' (we discussed this in using Shortcodes) within your site's root folder and add the highlited line below at the top of it
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

require_once( K_COUCH_DIR.'emailex.php' );

This will make our extension ('emailex.php') now a part of Couch.

Now for the Contact form.
There are two distinct things that need to be done
1. Upload a file
2. Send the uploaded file as Email attachment.

Upload a file
Since there is no cms:input tag in Couch (currently) that allows uploading of files, we have to take a little roundabout way.
In your form define the normal HTML input tag that is used for uploading e.g.
Code: Select all
<input type="file" name="my_file_ex">

Now immediately below it add a Couch input tag like this:
Code: Select all

This tag works as a sort of a proxy for the real 'input type="file"' tag above it and will do all the grunge work for us.
V.IMP: The thing that associates this tag with the real tag is the 'name' parameter. If the cms:input tag's name is 'my_file', the real input tag's name should have a '_ex' appended to make it 'my_file_ex'.

Note the 'validator' parameter where we make use of a routine provided by our extension.
The 'max_size' is the maximum size (in KB) you wish to permit for the uploaded files.
The 'allowed_ext' is a list of permitted extensions. For the CVs that will be uploaded in your case, this setting could be

The 'required' parameter can be used to make the uploading of file mandatory or not.
This will take care of uploading a file. Now to send the email with this uploaded file attached.

Send the uploaded file as Email attachment

Normally, we check for the 'k_success' condition in our form before using cms:send_mail to send the mail with the submitted values.

Since the cms:send_mail does not support attachments, we'll now use a PHP routine provide by our extension instead. e.g.
Code: Select all
   EmailEx::send_mail( '', '', 'Subject', 'Message' );

This will automatically attach any uploaded to the mail being sent.

Following is a complete working sample form that sends email with attachments:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:form method="POST" enctype="multipart/form-data" anchor='0'>

   <cms:if k_success >
      <h3>Thank you for contacting us!</h3>
      <cms:capture into='my_message'>
         The following is an email sent by a visitor to your site:
         Name: <cms:show frm_name />
         Email: <cms:show frm_email />
         Message: <cms:show frm_message />
         EmailEx::send_mail( '<cms:show frm_email />', '', 'Feedback from your site', '<cms:show my_message />' );
   <cms:else />
      <cms:if k_error >
         <cms:each k_error >
            <li><cms:show item /></li>
      Name: <cms:input type="text" name="name" /><br />
      Email: <cms:input type="text" name="email" validator='email' required='1' /><br />
      Message: <cms:input type="textarea" name="message" /><br />
      Upload File: <input type="file" name="my_file_ex"><br />
      <input type="submit" value="Submit" name='submit'>

<?php COUCH::invoke(); ?>
(702 Bytes) Downloaded 397 times

Take care to set the enctype="multipart/form-data" attribute of your form for attachments to work. Also, use you own email address as recipient.

Please test this extension out and let me know it does the job.

Hi KK.....what can I are amazing...just amazing...just one concern...does this work with captcha??

thanks heaps...

does this work with captcha??

I don't see any reason why it wouldn't.
It is just a regular cms:input tag (with the validating routine doing all the work behind the scenes).

Try integrating it withe the form that you are already using and please let me know if this helped.

ehyyy, it works are the best really.....thanks for all the time you dedicate to me

now I just have a problem styling the form...and it's actually quite weird:

here there is what i should obtain

Screen shot 2012-05-03 at 4.02.38 PM.png
Screen shot 2012-05-03 at 4.02.38 PM.png (19.02 KiB) Viewed 6607 times

but there are some notes:

how can I put just writing in the middle of the form and how can i put some filds with now name or label??

I tried but if i just add the writing it put's randomly in the form and if i put the fields with no label it just add me the actual name of the field....any solution??

thanks again you guys are awesome :D
I'm not sure I understood your questions entirely. Nevertheless, to create something like the screenshot you could use many methods. I believe labels and text inputs are 'inline' by default, so not much CSS is required.
Code: Select all
<label for="relationship_time">For how many months have you been in this relationship?:</label>
<cms:input type='text' name='relationship_time' />
<p>Dependent Children:</p>
<label for="child_1_name">Name:</label>
<label for="child_1_dob">DOB:</label>
<label for="child_1_name">Child 1:</label>
<cms:input type='text' name='child_1_name' />
<cms:input type='text' name='child_1_dob' />
<label for="child_2_name">Child 2:</label>
<cms:input type='text' name='child_2_name' />
<cms:input type='text' name='child_2_dob' />
<cms:input type='submit' value='Send' />
To create the desired spacing, you would need to apply further styling. Alternatively, you could use floats or inline-block styling to accomplish this.
Hi, my problem was just to hide some labels and a clear:both problem...everything is fixed, thanks for your time guys
Downloaded and tested. Thanks a lot, KK.
Using this on my form where I have to let the user upload 3 - 4 images.
Thanks again..
I'm having a problem with this script. It worked fine on my production xampp server, but I can't get it work on the deployment server. Send mail works fine, and even this script works fine if there are no attachments, however, when I use a form to upload attachment images, I just get "Failed to send email".

At first I also ran into trouble with normal couch admin panel file uploads, those turned out to be because of faulty permissions, but I got those sorted out.

Still, I cannot get mails with attachments to get sent from the server (hosting is on all-inkl). Do you have any idea what the problem might be, or how I could get at least a more useful error message?

I had a similar trouble once with GoDaddy and had to modify the script a little.
I'm attaching it here. Please test if it works for you.

Do let me know how it goes.


20 posts Page 1 of 2

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest