Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Form wont show content



7:36 pm on Feb 12, 2011 (gmt 0)

5+ Year Member

Hi I wrote following form processing script that I got partially to work. everything works (validation and adding name and email to header), but I can't get it to add the content in the body, I have saved all contents in the variable $body here it is:

function VerifyForm(&$values, &$errors)

if (strlen($values['name']) < 3)
$errors['name'] = 'Name too short';
elseif (strlen($values['name']) > 40)
$errors['name'] = 'Name too long';

if (!ereg('.*@.*\..{2,4}', $values['email']))
$errors['email'] = 'Email address invalid';

else {if(isset($_POST['submit'])){


$company = $_POST['company'];
$new_design = $_POST['new_design'];
$redesign = $_POST['redesign'];
$ecommerce = $_POST['ecommerce'];
$programming = $_POST['programming'];
$current_url = $_POST['current_url'];
$products = $_POST['products'];
$graphic = $_POST['graphic'];
$colors = $_POST['colors'];
$websites = $_POST['websites'];
$start = $_POST['start'];
$deadline = $_POST['deadline'];
$hosting = $_POST['hosting'];
$budget = $_POST['budget'];
$comment= $_POST['comment'];

return (count($errors) == 0);


function DisplayForm($values, $errors)

$body = "Confirmation: $confirm\n\n\n
Name: $name\n
Email: $email\n

Company: $company\n

Services selected:\n
products: $products\n
colors: $colors\n
websites I like: $websites\n
When Would you like to start: $start\n
Project deadline: $deadline\n
Budget: $budget\n

Details/Comments :$comment


all field are here



function ProcessForm($values)
mail('myemail@domain.com', "response" , $body, "From: \"{$values['name']}\ <{$values['email']}>");

echo "Sent ";

$formValues = $_POST;
$formErrors = array();

if (!VerifyForm($formValues, $formErrors))
DisplayForm($formValues, $formErrors);
DisplayForm(null, null);


10:11 pm on Feb 12, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there andy106,

Are you getting any errors at all when you run this script - if not I would strongly suggest that you set error_reporting(E_ALL) so that any errors can be displayed to the screen; also, the ereg function is now deprecated, I would suggest that you look at the manual and see advice given there wrt preg_match if you search for ereg functions.

Just to note, you can do this:-

if(!filter_var($input_address, FILTER_VALIDATE_EMAIL)){
//invalid email address
//valid email address

Great little function that negates the need for using any regex patterns, as the CONSTANT option flag that is used in filter_var() does this for you :)

And $body isn't being passed into the function, so there is no reference to this for the function to work as you intend.



10:53 pm on Feb 12, 2011 (gmt 0)

5+ Year Member

Hi Matthew, Thanks for getting back to me. I am not getting any error messages, I don't think there are any errors as you said for some reason $body is not being passed through the function, how would I be able to pass it through?

Thank you.



10:58 pm on Feb 12, 2011 (gmt 0)

5+ Year Member

by the way this :
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) worked great! thanks for that, so much easier that ereg.


12:07 am on Feb 13, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there andy106,

function ProcessForm($values, $body){
//do stuff

Just pass it through as another parameter, or if you want it as an optional thing:-

function ProcessForm($values, $body=null){
//do stuff

And yes, that little filter_vars function is quite handy isn't it ;p


Featured Threads

Hot Threads This Week

Hot Threads This Month