View Full Version : need to modify theis php form

03-17-2011, 03:17 AM
I need to modify this form to make it pretty:
and don't know how to do it!. I can follow directions, if someone want to share his/her knowledge, i will apreciate it: this is the code:


$yourEmail = "soapmaster@jabonesvioleta.com"; // the email address you wish to receive these mails through
$yourWebsite = "http://www.jabonesvioleta.com"; // the name of your website
$thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4


$error_msg = null;
$result = null;

function isBot() {
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot");

$isBot = false;
foreach ($bots as $bot)
if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
$isBot = true;

if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
$isBot = true;

exit("Bots not allowed.</p>");

function clean($data) {
$data = trim(stripslashes(strip_tags($data)));
return $data;

// lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
// score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
$points = (int)0;

$badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur");
$exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");

foreach ($badwords as $word)
if (strpos($_POST['comments'], $word) !== false)
$points += 2;

foreach ($exploits as $exploit)
if (strpos($_POST['comments'], $exploit) !== false)
$points += 2;

if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
$points += 2;
if (isset($_POST['nojs']))
$points += 1;
if (preg_match("/(<.*>)/i", $_POST['comments']))
$points += 2;
if (strlen($_POST['name']) < 3)
$points += 1;
if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
$points += 2;
// end score assignments

foreach ($_POST as $key => $value)
$_POST[$key] = trim($value);

if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
$error_msg .= "Name, e-mail and comments are required fields. \n";
} elseif (strlen($_POST['name']) > 15) {
$error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n";
} elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) {
$error_msg .= "The name field must not contain special characters. \n";
} elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) {
$error_msg .= "That is not a valid e-mail address. \n";
} elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
$error_msg .= "Invalid website url.";

if ($error_msg == NULL && $points <= $maxPoints) {
$subject = "Automatic Form Email";

$message = "You received this e-mail message through your website: \n\n";
foreach ($_POST as $key => $val) {
$message .= ucwords($key) . ": " . clean($val) . "\r\n";
$message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
$message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
$message .= 'Points: '.$points;

if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
$headers = "From: $yourEmail \r\n";
$headers .= "Reply-To: {$_POST['email']}";
} else {
$headers = "From: $yourWebsite <$yourEmail> \r\n";
$headers .= "Reply-To: {$_POST['email']}";

if (mail($yourEmail,$subject,$message,$headers)) {
if (!empty($thanksPage)) {
header("Location: $thanksPage");
} else {
$result = 'Your mail was successfully sent.';
} else {
$error_msg = 'Your mail could not be sent this time.';
} else {
if (empty($error_msg))
$error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
function get_data($var) {
if (isset($_POST[$var]))
echo htmlspecialchars($_POST[$var]);

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Email Form</title>
#example {
width: 350px;
border: 10px;
padding: 15px;
margin: 25px;

<style type="text/css">
margin:0 auto;
font-size: 16px;

.contact h3{
padding:5px 0;
font-family: "Times New Roman", Times, serif;
color: #000060;
font-weight: normal;
font-size: 2em;

.contact h5{
padding:0 0 10px 0;
font-family: "Times New Roman", Times, serif;
color: #606060;
font-weight: normal;
font-size: .8em;
text-transform: uppercase;
text-align: center;

.contact form{
background: #F2F8FC;
padding: 20px 10px 10px 10px;
margin: 0;

.contact h4{
padding:5px 10px 0 10px;
margin:-10px 0 0 10px;
background: #C8E0F4;
color: #000;
font-weight: normal;
font-size: .9em;
float: left;
border-style: solid;
border-color: #F2F8FC;
border-width: 1px 1px 0 1px;
border-top-right-radius: 5px;
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px;
border-top-left-radius: 5px;
-moz-border-radius-topleft: 5px;
-webkit-border-top-left-radius: 5px;

clear: both;
background: #C8E0F4;
padding:10px 10px 20px 10px;

.contact label{
width: 100px;
display: block;
float: left;
color: #3C3C3C;
font-size: .85em;

.contact p{
margin:5px 0;

.contact h6{
background: #C8E0F4;
padding: 15px;
margin: 5px;
color: #3C3C3C;
font-weight: normal;
font-size: .9em;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

.contact span{
font-weight: bold;
color: #000;
font-size: .95em;
p.error, p.success {
font-weight: bold;
padding: 10px;
border: 1px solid;
p.error {
background: #ffc0c0;
color: #f00;
p.success {
background: #b3ff69;
color: #4fa000;
label {
display: block;
margin: .5em 0 0 0;

.btn {
display: block;
margin: 1em 0;

<script type="text/javascript">
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }


Free PHP Mail Form v2.1.2 - Secure single-page PHP mail form for your website
Copyright (c) Jem Turner 2007, 2008, 2010

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

To read the GNU General Public License, see http://www.gnu.org/licenses/.

if ($error_msg != NULL) {
echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>";
if ($result != NULL) {
echo '<p class="success">'. $result . "</p>";
?><form action="<?php echo basename(__FILE__); ?>" method="post">

<div align="center">
<input type="hidden" name="nojs" id="nojs" />

<div style="background-color:#cccccc;color#00C">
<p align="center">How Can We Help You ?</p>
<p align="center">
<select name="howcanwehelpyou" id="howcanwehelpyou">
<option value="chooseone">Choose One</option>
<option value="wholesale">Wholesale</option>
<option value="fundraising">Fund Raising</option>
<option value="salesrep">Sales Rep</option>
<option value="privatelabeling">Private Labeling</option>
<p align="center">
<label for="name">Name: *<br />
<input type="text" name="name" id="name" value="<?php get_data("name"); ?>" />
<p align="center">
<label for="lastname">Last Name:*</label>
<input type="text" name="lastname" id="lastname" />
<p align="center">
<label for="phone">Phone:*</label>
<input name="phone" type="text" id="phone" onblur="MM_validateForm('phone','','R');MM_validateForm('l astname','','R');return document.MM_returnValue" />
<br />

<label for="email">E-mail: *</label>
<input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /><br /><br />

<label for="location">Location:</label>
<input type="text" name="location" id="location" value="<?php get_data("location"); ?>" /><br />

<label for="comments">Comments: *</label>
<textarea name="comments" id="comments" rows="5" cols="20"><?php get_data("comments"); ?></textarea>
<br />
<p align="center">
<input type="submit" name="submit" id="submit" value="Send Form" />


Thank you very Much in Advance

03-17-2011, 04:45 AM
I need to modify this form to make it pretty:

You need to better define what you want to do. Make it pretty by doing what exactly?

03-17-2011, 05:19 AM
sorry for the pretty word....I need to organize this form, be aligned so it can be symmetrical (as for now looks kind of messy) add some borders and
applying some styles ( which I don't know how)
for instance I saw somewhere that the label can appear on top instead of the left side of the box, etc . am reading to learn the proper terminology of php,html,css,coding.and if I can't explain this time I will be back in a week with perhaps the same question...and better knowledge of the terminology I thank you for your time

03-17-2011, 06:32 AM
I saw somewhere that the label can appear on top instead of the left side of the box
Just set the label element to display: block in your CSS.

You can also set your form inputs to display: block and give them widths and heights in your CSS, so that you can style them pretty.

This article might be something for you:

03-19-2011, 12:45 PM
I thank you very much, for helping me to accomplish, what was in my mind.
with your advice learned how to use styles...
also some other variables as well.
my form looks great .. but is not ready yet :).hope it will be soon so i can share with all of you.
I will post another tread..