You are here: Home » All Posts » Contact Forms » Making a contact form with file upload support

Making a contact form with file upload support

in Contact Forms

Having file upload boxes in contact forms will be greatly convenient for some web sites. For example, if the visitor can attach his/her photo and resume, that will greatly enhance the form's functionality. Here is a contact form that you can customize for your needs.

Download the contact form code

You can download the contact form that best fits your needs and then customize as required.

Contact form with file attachment
A simple contact form with a file upload field
Try the DemoDownload
Contact form with file attachment and Captcha
Contact form with file upload field and Captcha
Try the DemoDownload
Contact form with file uploads
Contact form with two file upload fields and Captcha
Try the DemoDownload

Features of the contact form

  • You can have any number of file upload boxes
  • Standards compliant (100% XHTML 1.0 strict validated, uses CSS)
  • Secured against spam bots and attacks
  • Easy to customize
  • Hosted on your own web server
  • Free!

Installing the contact form on your web site

  1. Unzip the downloaded contact form code.
  2. Edit contactform.php and edit the email address to your email address
  3. $formproc->AddRecipient('name@your-website.com');//<<---Put your email address here
    
  4. Upload the folder contents to your website (to a sub-folder say, /contact)
  5. The contactform.php contains the form. You can link to this file or embed the form using iframe.
  6. Here is sample iframe code to embed the form:

    <iframe src='/contact/contactus.php' frameborder='0'
    width='100%' height='600' ></iframe>
    

    Alternatively, you can modify contactform.php to have the same look of your web site.

Customizing the form

If you want to add one more file upload box, do the following:

  1. open contactus.php in a text editor
  2. Add the HTML code for the file upload box(just like the existing one for the photo). Gove another unique name and id for the file upload box
  3. <div class='container'>
        <label for='photo' >Another upload:</label><br/>
        <input type="file" name='newupload' id='newupload' /><br/>
        <span id='contactus_newupload_errorloc' class='error'></span>
    </div>
    
  4. Add one more line on the top of the contactus.php
  5. $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
    $formproc->AddFileUploadField('resume','doc,docx,pdf,txt',2024);
    $formproc->AddFileUploadField('newupload','',2024);//<<------- New file upload
    

You can edit the contact.css file to change the style of the form.

License


The code is shared under LGPL license. You can freely use it on commercial or non-commercial websites.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. A simple, easy PHP contact form
  2. Creating a contact form for your website

{ 138 comments… read them below or add one }

stu January 16, 2012 at 9:30 pm

hi, great form… mines working perfectly with a few of my own css and tweaks… BUT, is there a way to put the error messages in a separate div??

my form is hidden in a ‘show/hide’ div and when the form is filled out incorrectly the div re-sets and hides the form. So if someone does fill it out wrong they are unaware… i need the error messages to be displayed in a separate div like a separate container or column…

anyone got an idea???

Reply

Jaison January 18, 2012 at 10:58 am

I’ve been looking for a way to allow users to send pictures to me through my blog. This is the best solution I found. Thank you very much

Reply

Serge Pavloff January 18, 2012 at 11:17 pm

Hi, form was very easy to install – so big thanks for that…I just got one problem,
I’m trying to add more file formats such as .doc, .txt etc.
so where do I need to upload this line and do I need to change something in validation query?
$formproc->AddFileUploadField(‘resume’,'doc,docx,pdf,txt’,2024);
I’m total newbie and been learning html/php only for the last 2 months..so plz help me out..
Thanks

Reply

s January 20, 2012 at 1:24 am

Hi,

Just wanted to say a massive thank you for this. I’ve been trying to get a basic form on my site for two days! Non of the other scripts worked for me, but this worked like a charm.

TIP: Once you have downloaded the the file, unzip it directly into your website folder. That way files will by linked with each other without you having to change any text/codes (apart from one, which is the email you want it sent two).

I’m using Dreamweaver CS5, hosted by: 000webhost.

Reply

s January 20, 2012 at 1:24 am

Now just need to tweak it to my taste!

Reply

Aiden January 21, 2012 at 9:14 am

Nice work for this, this is very helpful, thumbs up for you guys but how to remove this kind of error? I ecountered that error after I sent the message instead of thank-you.php

thanks a lot and I’m hoping for the response.

Deprecated: Function eregi() is deprecated in /home/akai1831/public_html/contact/include/fgcontactform.php on line 548

Deprecated: Function split() is deprecated in /home/akai1831/public_html/contact/include/class.phpmailer.php on line 470

Reply

modasser February 10, 2012 at 1:13 pm

I’m getting the same problem on xampp.
Deprecated: Function eregi() is deprecated in C:\xampp\htdocs\dailyrozgar\contactUs\include\fgcontactform.php on line 548

So, what is the solution please?

Reply

asa January 22, 2012 at 5:37 pm

Hello if i use the iframe how can i set the link page to appear in the same window and not in the iframe? where to put target=”_top” ?

Reply

Larry January 25, 2012 at 10:24 pm

Form works in that it sends email, but not attachments. The email lists the files to be uploaded, but the email has no attachments.

Reply

jhon February 1, 2012 at 1:48 am

how to create a contact form on xampp?
how to connect to the database?
and what field created in the database?

Reply

Govind February 3, 2012 at 5:59 am

wow…it’s working fine.

Reply

Paul February 6, 2012 at 9:51 pm

Got the form working great for customers to send us a logo. Customers also has to specify 4 SKU #s in order for us to make customized sewing machine needle gift boxes for them. When you look at the page there is a lot of empty real-estate to the right of the form. Here’s my question: Colleague is wondering if I can add a list of SKU’s to the space to the right of the form. I’ve been banging my head against the wall trying to come up with a solution. The code as currently generated doesn’t allow me to do any editing/adding to the right of the form. I’ve tried to set up a a two-column page with the form on the left and my SKU’s on the right . . . unfortunately, things become hopelessly messed up. Anyone have any solutions????

Reply

peter February 7, 2012 at 4:03 am

Hi, i am using a php form with file upload, and everything works great except i dont get the uploaded file such as jpg to my gmail, please help
thanks

Reply

Klim February 11, 2012 at 3:39 pm

Hello, i can’t align the iframe on the center on my home page, do you know how i can do this, i try a lot of solution but nothing work. Thanks

Reply

hendra February 13, 2012 at 8:52 am

hi.. please tell me how to change above coding if i dont want send the uploaded file to my email, but to my directory website. cause maybe visitor upload big size file. sorry i am still newbie in PHP. thx before

Reply

macroll February 15, 2012 at 11:51 am

Perfect, it works

Reply

scott February 15, 2012 at 8:42 pm

I keep getting

“Automated submission prevention: case 1 failed”

Even when I fill out the demo forms? Does anybody know why?

Reply

JohannaR February 16, 2012 at 8:27 am

I set up form which worked nicely till i tried it with Internet Explorer. It doesn’t work at all! I have all the latest updates for it, and still don’t do the trick. Why it doesn’t support IE? With Mozilla it works just fine.

Reply

Prasanth February 17, 2012 at 2:37 pm

Please try the sample forms in this page in IE. Does it work?

Reply

JohannaR February 16, 2012 at 9:43 am

I may have cried a bit too early. I made the whole form again and now it seem to work – phew!

Reply

Leave a Comment

Previous post:

Next post: