/*
########################## Contact Form 1.3 #########################
### |-----------------------------------------------------------| ###
### | WRITTEN 2006 by planetluc.com c/o Lukas Stalder | ###
### | THIS SMALL SCRIPT IS FREE AND MAY BE REDISTRIBUTED | ###
### |-----------------------------------------------------------| ###
#####################################################################
*/
/*
// ################ INSTALLATION #################
1. open the .php file where you want to have the contact form in.
2. paste this whole code in there
3. adapt values in the config section below to your needs.
4. upload the file - that's it!
// ############## END INSTALLATION ###############
*/
// ################### CONFIG ###################
// CSS classes & styles
$classError = "error"; // class for error messages below input fields
$classTxt = "text"; // class for field caption cell
$classField = "field"; // class for input/textarea field cell
$classInputbutton = "inputButton"; // class for submit button
$classInputline = "inputLine"; // class for input lines
$classInputfield = "inputField"; // class for textareas
$styleInputline = "width:355px;"; // add. styles for input lines
$styleInputfield = "width:355px; height:100px;"; // add. styles for textareas
$styleInputbutton = "width:355px;"; // add. styles for submit button
$styleInputradio = "vertical-align:middle;"; // add. styles for radio input fields
$styleInputselect = "width:355px;";
// email
$targetAddress = "lwagency@cox.netm";
$emailSubject = "Piperlen.com Website Request";
// misc text
$txtSend = "Send";
$txtMandatory = "mandatory";
$msgDate = "Date";
$dateFormat = "d. M Y, H:i";
$msgIndent = 11;
//thank you messages
$txtThankyou = "Thank you for getting in contact with us!Your request has been sent and you'll be contacted as soon as possible.";
// form fields
/*
every form field is an array consisting of 6 elements:
1) field caption
2) field name
3) field type: line, field, radio
4) additional info: if field type is
- 'radio' this field contains the radio captions/values like so: {caption1|value1} {caption2|value2} {caption3|value3}...
- 'select' this field contains the radio captions/values like so: {caption1|value1} {caption2|value2} {caption3|value3}...
- 'email' the field value must be a valid emailaddress
5) mandatory ('*') or not ('')
6) error message if empty on submit and set to mandatory previously
*/
$fields[] = array("Company", "company", "line", "", "", "");
$fields[] = array("Name", "name", "line", "", "*", "Please enter a name");
$fields[] = array("Address", "address", "line", "", "", "");
$fields[] = array("Zip/City", "city", "line", "", "", "");
$fields[] = array("Phone", "phone", "line", "", "*", "Please enter a phone number");
$fields[] = array("Email", "email", "line", "email", "*", "Please enter a valid email address");
$fields[] = array("Reply by", "replyby", "radio", "{Email|by email}{Phone|by phone}{Post|by post}", "*", "Please select a reply mode");
$fields[] = array("Request", "request", "field", "", "*", "Please enter a request");
// ################ END CONFIG ##########################################################
// #######################################################################################
$version = "1.3";
function spaces($num, $fill=" "){
$foo="";
for ($i=0; $i<$num; $i++) $foo.=$fill;
return $foo;
}
function isValidEmail($addr){
if(eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$", $addr))
return true;
else
return false;
}
// start form evaluation
unset($error);
if ($_REQUEST['do']=="send"){
$error = false;
$fromAddress = "";
$message = "";
foreach ($fields as $field){
if ($field[4] == "*"){
if ($field[3] == "email"){
if (!isValidEmail($_REQUEST[$field[1]])) $error[$field[1]] = $field[5];
}else{
if ($_REQUEST[$field[1]] == "") $error[$field[1]] = $field[5];
}
}
}
if ($error === false){
$message = $emailSubject." \n";
for ($i = 0; $i < strlen($emailSubject); $i++) $message .= "*";
$message .= " \n\n$msgDate:".spaces($msgIndent-strlen($msgDate)).date($dateFormat);
foreach ($fields as $field){
$message .= "\n".$field[0].":".spaces($msgIndent-strlen($field[0]));
if ($field[3] == "email"){
$message .= "mailto:".$_REQUEST[$field[1]];
$fromAddress = "From: ".$_REQUEST[$field[1]];
}else $message .= $_REQUEST[$field[1]];
$message .= " ";
}
mail($targetAddress, $emailSubject, $message, $fromAddress);
echo $txtThankyou;
}
}
if ($error!==false){
// draw form
echo "\n\n \n\n";
echo "\n";
echo "\n \n\n";
}
/*
######################### END Contact Form ##########################
#####################################################################
*/
?>
|