All times are UTC + 5:30 hours




Post new topic Reply to topic  [ 7 posts ] 
  Print view

File attachments in Contact form
Author Message
PostPosted: Tue May 01, 2012 7:52 am 
Registered User
Offline

Joined: Sun Jul 17, 2011 8:23 am
Posts: 37
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 implemented...is there a patch?? please guys help me....

love
Emanuele

LOL


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Wed May 02, 2012 6:51 am 
Moderator
Offline

Joined: Wed Dec 01, 2010 5:35 pm
Posts: 1378
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.
Attachment:
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
Quote:
<?php
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:
<input type="file" name="my_file_ex">

Now immediately below it add a Couch input tag like this:
Code:
<cms:input
   type="hidden"
   name="my_file"
   required='1'
   validator='EmailEx::validate=max_size:512&allowed_ext:jpeg,jpg,gif,png'
   value='1'
/>

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
Quote:
validator='EmailEx::validate=max_size:512&allowed_ext:doc,txt'

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:
<cms:php>
   EmailEx::send_mail( 'sender@mail.com', 'receiver@mail.com', 'Subject', 'Message' );
</cms:php>

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

Following is a complete working sample form that sends email with attachments:
Code:
<?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 />
      </cms:capture>
     
      <cms:php>
         EmailEx::send_mail( '<cms:show frm_email />', 'youraddress@gmail.com', 'Feedback from your site', '<cms:show my_message />' );
      </cms:php>
     
   <cms:else />
      <cms:if k_error >
         <ul>
         <cms:each k_error >
            <li><cms:show item /></li>
         </cms:each>
         </ul>
      </cms:if>
     
      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 />
      <cms:input
         type="hidden"
         name="my_file"
         required='1'
         validator='EmailEx::validate=max_size:512&allowed_ext:jpeg,jpg,gif,png,txt'
         value='1'
      />
     
      <input type="submit" value="Submit" name='submit'>
   </cms:if>
   
</cms:form>


<?php COUCH::invoke(); ?>

Attachment:
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.

Thanks.


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Wed May 02, 2012 8:38 am 
Registered User
Offline

Joined: Sun Jul 17, 2011 8:23 am
Posts: 37
Hi KK.....what can I say...you are amazing...just amazing...just one concern...does this work with captcha??

thanks heaps...

Emanuele


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Wed May 02, 2012 5:30 pm 
Moderator
Offline

Joined: Wed Dec 01, 2010 5:35 pm
Posts: 1378
Quote:
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.

Thanks.


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Thu May 03, 2012 11:36 am 
Registered User
Offline

Joined: Sun Jul 17, 2011 8:23 am
Posts: 37
ehyyy, it works fine....you 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

Attachment:
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 1063 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


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Thu May 03, 2012 1:36 pm 
Registered User
Offline

Joined: Thu Oct 13, 2011 2:48 am
Posts: 258
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:
<div>
<label for="relationship_time">For how many months have you been in this relationship?:</label>
<cms:input type='text' name='relationship_time' />
</div>
<p>Dependent Children:</p>
<div>
<label for="child_1_name">Name:</label>
<label for="child_1_dob">DOB:</label>
</div>
<div>
<label for="child_1_name">Child 1:</label>
<cms:input type='text' name='child_1_name' />
<cms:input type='text' name='child_1_dob' />
</div>
<div>
<label for="child_2_name">Child 2:</label>
<cms:input type='text' name='child_2_name' />
<cms:input type='text' name='child_2_dob' />
</div>
<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.


Top
 Profile  
 

Re: File attachments in Contact form
PostPosted: Wed May 09, 2012 6:44 am 
Registered User
Offline

Joined: Sun Jul 17, 2011 8:23 am
Posts: 37
Hi, my problem was just to hide some labels and a clear:both problem...everything is fixed, thanks for your time guys


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 5:30 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
© 2001-2010 SYS-Solutions All Rights Reserved