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.
emailex.zip [7.78 KiB]
Downloaded 59 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.
<input type="file" name="my_file_ex">
Now immediately below it add a Couch input tag like this:
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.
EmailEx::send_mail( 'email@example.com', 'firstname.lastname@example.org', '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:
<?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>
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 />', 'email@example.com', 'Feedback from your site', '<cms:show my_message />' );
<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(); ?>
sample.zip [702 Bytes]
Downloaded 66 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.