Form with CMS

5 posts by 3 authors in: Forums > CMS Builder
Last Post: June 23, 2011   (RSS)

By dccreatives - June 21, 2011

I am using a form on my web site for customer support

<?php
require_once "../cmsAdmin/lib/init.php";

// process form
if (@$_REQUEST['submitForm']) {

// error checking
$errorsAndAlerts = "";
if ([url "mailto:!@$_REQUEST['fullname'"]!@$_REQUEST['fullname'[/url]]) { $errorsAndAlerts .= "You must enter your full name!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['email'"]!@$_REQUEST['email'[/url]]) { $errorsAndAlerts .= "You must enter your email!<br/>\n"; }
else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts .= "Please enter a valid email (example: user@example.com)<br/>\n"; }
if ([url "mailto:!@$_REQUEST['message'"]!@$_REQUEST['message'[/url]]) { $errorsAndAlerts .= "You must enter a message!<br/>\n"; }

// send email user
if (!$errorsAndAlerts) {
$from = $_REQUEST['email'];
$to = "test@test.com";
$subject = "Email form submitted from {$_SERVER['HTTP_HOST']}";
$message = <<<__TEXT__
You've received an email from the email form here:
[url "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME'"]http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME'[/url]]}

Full name: {$_REQUEST['fullname']}
Email: {$_REQUEST['email']}
Message: {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
// Note: The above line must be flush left or you'll get an error
// This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

// send message
$mailResult = @mail($to, $subject, $message, "From: $from");
if (!$mailResult) { die("Mail Error: $php_errormsg"); }

//
$errorsAndAlerts = "Thank you for contacting Axis Lighting. We will do our best to get back to you as quickly as possible.";
$_REQUEST = array(); // clear form values
}

}

?>



My question is can I make it have a field to upload an attachment as well?

Re: [dccreatives] Form with CMS

By gkornbluth - June 22, 2011

Hi dccreatives,

Just my two cents.

If you're using a contact form and also need the form to handle uploading a file or files, you might want to consider including at least a rudimentary form of CAPTCHA security in the process.

There are a few really flexible, free, third party solutions to forms that handle uploads discussed in my CMSB Cookbook http://www.thecmsbcookbook.com.

The file handling can include storing them on the server and the programs take care of a lot of "housekeeping" details as well.

Hope they give you some good ideas.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [dccreatives] Form with CMS

By Jason - June 23, 2011

Hi,

I did a google search for "PHP contact form with upload and got quite a few results returned.

Here is one article that looked like it matched what you're looking for:
http://www.html-form-guide.com/email-form/php-email-form-attachment.html

I haven't tried this myself, but it looks like it should get you pointed in the right direction.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [dccreatives] Form with CMS

By Jason - June 23, 2011

Hi,

The form code is probably fine, the issue will be handling the file upload.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/