Jump to content

Recommended Posts

Hi guys,

 

Here is a validation script that i am working on and i am having trouble passing the one variable ($messageSend) I am not getting the $messageSend = "true" to pass even through the "$messageError = $approvedMessage;" right before it with in the same else statement is working fine? When I echo $messageSend the result is undefined? I know it a big script but the trouble area is in the script tags below

 

Please Help

 

Thanks

 

 

<?php require_once('Connections/GetWebContent.php'); ?>

<?php

 

if(!($_GET[start]=="false")){ // start

 

$populateFirstName = $_POST[firstName];

$populateLastName = $_POST[lastName];

$populateEmallAddress = $_POST[emailAddress];

$populatePhoneNumber = $_POST[phoneNumber];

$populateMobileNumer = $_POST[mobileNumber];

$populateStreet = $_POST[street];

$populateSuburb = $_POST[suburb];

$populatePostalCode = $_POST[postalCode];

$populateCountry = $_POST[country];

$populateTown = $_POST[town];

$populateMessage = $_POST[message];

 

function validateNames($name, $errorMessage, $approvedMessage, $fieldName, $runExperssion ){// 2

global $firstNameError;

global $lastNameError;

global $emailAddressError;

global $phoneNumberError;

global $mobileNumberError;

global $streetError;

global $suburbError;

global $postalCodeError;

global $townError;

global $countryError;

global $messageError;

global $spamError;

 

global $firstNameSend;

global $lastNameSend;

global $emailAddressSend;

global $phoneNumberSend;

global $mobileNumberSend;

global $streetSend;

global $suburbSend;

global $postalCodeSend;

global $townSend;

global $countrySend;

global $messageSend;

 

//validate first name

if($name == "" && $fieldName == "firstName"){

$firstNameError = $errorMessage;

}elseif(!eregi("^[a-z']{2,35}$", $_POST[firstName]) && $runExperssion == "run" && $fieldName == "firstName"){

$firstNameError = $errorMessage;

$firstNameSend = "false";

}elseif(eregi("^[a-z']{2,35}$", $_POST[firstName]) && $runExperssion == "run" && $fieldName == "firstName"){

$firstNameError = $approvedMessage;

$firstNameSend = "true";

};

// validate last name

if($name == "" && $fieldName == "lastName"){

$lastNameError = $errorMessage;

}elseif(!eregi("^[a-z']{2,35}$", $_POST[lastName]) && $runExperssion == "run" && $fieldName == "lastName"){

$lastNameError = $errorMessage;

$lastNameSend = "false";

}elseif(eregi("^[a-z']{2,35}$", $_POST[lastName]) && $runExperssion == "run" && $fieldName == "lastName"){

$lastNameError = $approvedMessage;

$lastNameSend = "true";

};

// validate email address

if($name == "" && $fieldName == "emailAddress"){

$emailAddressError = $errorMessage;

}elseif(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]{2,5}$", $_POST[emailAddress]) && $runExperssion == "run" && $fieldName == "emailAddress"){

$emailAddressError = $errorMessage;

$emailAddressSend = "false";

}elseif(eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]{2,5}$", $_POST[emailAddress]) && $runExperssion == "run" && $fieldName == "emailAddress"){

$emailAddressError = $approvedMessage;

$emailAddressSend = "true";

};

 

// valdate phone number

 

if($name == "" && $fieldName == "phoneNumber"){

$phoneNumberError = $errorMessage;

}elseif(!eregi("^[0-9()+ ]{7,25}$", $_POST[phoneNumber]) && $runExperssion == "run" && $fieldName == "phoneNumber"){

$phoneNumberError = $errorMessage;

$phoneNumberSend = "false";

}elseif(eregi("^[0-9()+ ]{7,25}$", $_POST[phoneNumber]) && $runExperssion == "run" && $fieldName == "phoneNumber"){

$phoneNumberError = $approvedMessage;

$phoneNumberSend = "true";

};

// validate mobile number

if($name == "" && $fieldName == "mobileNumber"){

$mobileNumberError = $errorMessage;

}elseif(!eregi("^[0-9()+ ]{7,25}$", $_POST[mobileNumber]) && $runExperssion == "run" && $fieldName == "mobileNumber"){

$mobileNumberError = $errorMessage;

$mobileNumberSend = "false";

}elseif(eregi("^[0-9()+ ]{7,25}$", $_POST[mobileNumber]) && $runExperssion == "run" && $fieldName == "mobileNumber"){

$mobileNumberError = $approvedMessage;

$mobileNumberSend = "true";

};

 

 

// validate steer name and number

if($name == "" && $fieldName == "street"){

$streetError = $errorMessage;

}elseif(!eregi("^[a-z0-9'. ]{2,40}$", $_POST[street]) && $runExperssion == "run" && $fieldName == "street"){

$streetError = $errorMessage;

$streetSend = "false";

}elseif(eregi("^[a-z0-9'. ]{2,40}$", $_POST[street]) && $runExperssion == "run" && $fieldName == "street"){

$streetError = $approvedMessage;

$streetSend = "true";

};

// validate suburb

if($name == "" && $fieldName == "suburb"){

$suburbError = $errorMessage;

}elseif(!eregi("^[a-z'.0-9 ]{2,35}$", $_POST[suburb]) && $runExperssion == "run" && $fieldName == "suburb"){

$suburbError = $errorMessage;

$suburbSend = "false";

}elseif(eregi("^[a-z'.0-9 ]{2,35}$", $_POST[suburb]) && $runExperssion == "run" && $fieldName == "suburb"){

$suburbError = $approvedMessage;

$suburbSend = "true";

};

// validate postal code

if($name == "" && $fieldName == "postalCode"){

$postalCodeError = $errorMessage;

}elseif(!eregi("^[0-9]{2,6}$", $_POST[postalCode]) && $runExperssion == "run" && $fieldName == "postalCode"){

$postalCodeError = $errorMessage;

$postalCodeSend = "false";

}elseif(eregi("^[0-9]{2,6}$", $_POST[postalCode]) && $runExperssion == "run" && $fieldName == "postalCode"){

$postalCodeError = $approvedMessage;

$postalCodeSend = "true";

};

// validate town

if($name == "" && $fieldName == "town"){

$townError = $errorMessage;

}elseif(!eregi("^[a-z'. ]{2,35}$", $_POST[town]) && $runExperssion == "run" && $fieldName == "town"){

$townError = $errorMessage;

$townSend = "false";

}elseif(eregi("^[a-z'. ]{2,35}$", $_POST[town]) && $runExperssion == "run" && $fieldName == "town"){

$townError = $approvedMessage;

$townSend = "true";

};

// validate country

if($name == "0" && $fieldName == "country"){//1

$countryError = $errorMessage;

$countrySend = "false";

}elseif($name <> "0" && $fieldName == "country"){

$countryError = $approvedMessage;

$countrySend = "true";

}//1

 

// validate message box

if($name == "" && $fieldName == "message"){
	$messageError = $errorMessage;
	$messageSend = "false";
	}elseif($name <> "" && $fieldName == "message"){
		$messageError = $approvedMessage;
		$messageSend == "true";
	};

// validate spam number

if($name == "" && $fieldName == "spam"){

$spamError = $errorMessage;

$spamSend = "false";

}elseif($name <> $_POST[spamNumber]){

$spamError = $errorMessage;

$spamSend = "false";

}elseif($name == $_POST[spamNumber]){

$spamError = $approvedMessage;

$spamSend = "true";

};

};//2 end funtion validate Name

 

 

// generated random number for spam check

$spamNumber = rand(1000,9999);

 

$approvedMark = "<img src='img/approvedMark.jpg' width='20' height='15' />";

$rejectMark = "<img src='img/rejectMark.jpg' width='15' height='15'/>";

 

validateNames($_POST[firstName], $rejectMark, $approvedMark, "firstName", "run");

validateNames($_POST[lastName], $rejectMark, $approvedMark, "lastName", "run");

validateNames($_POST[emailAddress], $rejectMark, $approvedMark, "emailAddress", "run");

validateNames($_POST[phoneNumber], $rejectMark, $approvedMark, "phoneNumber", "run");

validateNames($_POST[mobileNumber], $rejectMark, $approvedMark, "mobileNumber", "run");

validateNames($_POST[street], $rejectMark, $approvedMark, "street", "run");

validateNames($_POST[suburb], $rejectMark, $approvedMark, "suburb", "run");

validateNames($_POST[postalCode], $rejectMark, $approvedMark, "postalCode", "run");

validateNames($_POST[town], $rejectMark, $approvedMark, "town", "run");

validateNames($_POST[country],$rejectMark, $approvedMark, "country", "run");

validateNames($_POST[message], $rejectMark, $approvedMark, "message", "run");

validateNames($_POST[spam], $rejectMark, $approvedMark, "spam", "run");

 

 

 

 

function validateDate($fieldDay, $fieldMonth, $fieldYear, $rejectMessage, $approvedMessage){

global $dateError;

global $dateSend;

 

 

if($fieldDay == "0" || $fieldMonth =="0" || $fieldYear == "0"){//1

$dateError = $rejectMessage;

$dateSend = "false";

return false;

};//1

if($fieldMonth == "4" || $fieldMonth == "6" || $fieldMonth == "9" || $fieldMonth == "11"){//1

if($fieldDay > "30" ){//2

$dateError = $rejectMessage;

$dateSend = "false";

}else{

$dateError = $approvedMessage;

$dateSend = "true";

};//2

}else{

$dateError = $approvedMessage;

$dateSend = "true";

};//1

if($fieldMonth == "2" && $fieldDay > "28"){//3

if($fieldYear % 4 == 0 && $fieldDay <= "29"){//4

$dateError = $approvedMessage;

$dateSend = "true";

if($fieldYear % 100 == 0 && $fieldDay > "28"){//5

$dateError = $rejectMessage;

$dateSend = "false";

if($fieldYear % 400 == 0 && $fieldDay <= "29"){//6

$dateError = $approvedMessage;

$dateSend = "true";

}else{

$dateError = $rejectMessage;

$dateSend = "false";

};//6

}else{

$dateError = $approvedMessage;

$dateSend = "true";

};//5

}else{

$dateError = $rejectMessage;

$dateSend = "false";

};//4

};//3

 

};// function validateDate end

 

validateDate($_POST[day], $_POST[month], $_POST[year], $rejectMark, $approvedMark);

 

//echo "firstName ".$firstNameSend."</br>";

//echo "lastName ".$lastNameSend."</br>";

//echo "date ".$dateSend."</br>";

//echo "emailAddess ".$emailAddressSend."</br>";

//echo "phoneNumber ".$phoneNumberSend."</br>";

//echo "mobileNumber ".$mobileNumberSend."</br>";

//echo "street ".$streetSend."</br>";

//echo "suburb ".$suburbSend."</br>";

//echo "postalCoce ".$postalCodeSend."</br>";

//echo "town ".$townSend."</br>";

//echo "country ".$countrySend."</br>";

echo "message ".$messageSend."</br>";

if($firstNameSend == "true" && $lastNameSend == "true" && $emailAddressSend == "true" && $phoneNumberSend == "true" && $mobileNumberSend == "true" && $streetSend == "true" && $suburbSend == "true" && $postalCodeSend == "true" && $townSend == "true" && $countrySend == "true" && $messageSend == "true" && $dateSend == "true"){
//	$sendMail
echo "Message will Sendddd";
}else{
echo "Mesagge not sent!!!!!!!!!!!!!!!!";
};

 

 

};

 

 

?>

 

 

thats too hard to read..

 

heres a clean version

 

i updated one line

$messageSend = "true"; // Changed == to =

 

EDIT:

Not really a syntax error but will not set the variable

 

<?php require_once('Connections/GetWebContent.php'); ?>
<?php

if(!($_GET[start]=="false")){ // start

$populateFirstName = $_POST[firstName];
$populateLastName = $_POST[lastName];
$populateEmallAddress = $_POST[emailAddress];
$populatePhoneNumber = $_POST[phoneNumber];
$populateMobileNumer = $_POST[mobileNumber];
$populateStreet = $_POST[street];
$populateSuburb = $_POST[suburb];
$populatePostalCode = $_POST[postalCode];
$populateCountry = $_POST[country];
$populateTown = $_POST[town];
$populateMessage = $_POST[message];

function validateNames($name, $errorMessage, $approvedMessage, $fieldName, $runExperssion ){// 2
global $firstNameError;
global $lastNameError;
global $emailAddressError;
global $phoneNumberError;
global $mobileNumberError;
global $streetError;
global $suburbError;
global $postalCodeError;
global $townError;
global $countryError;
global $messageError;
global $spamError;

global $firstNameSend;
global $lastNameSend;
global $emailAddressSend;
global $phoneNumberSend;
global $mobileNumberSend;
global $streetSend;
global $suburbSend;
global $postalCodeSend;
global $townSend;
global $countrySend;
global $messageSend;

//validate first name
if($name == "" && $fieldName == "firstName"){
	$firstNameError = $errorMessage;
	}elseif(!eregi("^[a-z']{2,35}$", $_POST[firstName]) && $runExperssion == "run" && $fieldName == "firstName"){
		$firstNameError = $errorMessage;
		$firstNameSend = "false";
	}elseif(eregi("^[a-z']{2,35}$", $_POST[firstName]) && $runExperssion == "run" && $fieldName == "firstName"){
		$firstNameError = $approvedMessage;
		$firstNameSend = "true";
		};
// validate last name	
if($name == "" && $fieldName == "lastName"){
	$lastNameError = $errorMessage;
}elseif(!eregi("^[a-z']{2,35}$", $_POST[lastName]) && $runExperssion == "run" && $fieldName == "lastName"){
	$lastNameError = $errorMessage;
	$lastNameSend = "false";
	}elseif(eregi("^[a-z']{2,35}$", $_POST[lastName]) && $runExperssion == "run" && $fieldName == "lastName"){
		$lastNameError = $approvedMessage;
		$lastNameSend = "true";
	};
// validate email address
if($name == "" && $fieldName == "emailAddress"){
	$emailAddressError = $errorMessage;
	}elseif(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]{2,5}$", $_POST[emailAddress]) && $runExperssion == "run" && $fieldName == "emailAddress"){
		$emailAddressError = $errorMessage;
		$emailAddressSend = "false";
	}elseif(eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]{2,5}$", $_POST[emailAddress]) && $runExperssion == "run" && $fieldName == "emailAddress"){
		$emailAddressError = $approvedMessage;
		$emailAddressSend = "true";
	};

// valdate phone number

if($name == "" && $fieldName == "phoneNumber"){
	$phoneNumberError = $errorMessage;
	}elseif(!eregi("^[0-9()+ ]{7,25}$", $_POST[phoneNumber]) && $runExperssion == "run" && $fieldName == "phoneNumber"){
		$phoneNumberError = $errorMessage;
		$phoneNumberSend = "false";
	}elseif(eregi("^[0-9()+ ]{7,25}$", $_POST[phoneNumber]) && $runExperssion == "run" && $fieldName == "phoneNumber"){
		$phoneNumberError = $approvedMessage;
		$phoneNumberSend = "true";
	};
// validate mobile number
if($name == "" && $fieldName == "mobileNumber"){
	$mobileNumberError = $errorMessage;
	}elseif(!eregi("^[0-9()+ ]{7,25}$", $_POST[mobileNumber]) && $runExperssion == "run" && $fieldName == "mobileNumber"){
		$mobileNumberError = $errorMessage;
		$mobileNumberSend = "false";
	}elseif(eregi("^[0-9()+ ]{7,25}$", $_POST[mobileNumber]) && $runExperssion == "run" && $fieldName == "mobileNumber"){
		$mobileNumberError = $approvedMessage;
		$mobileNumberSend = "true";
	};	


// validate steer name and number
if($name == "" && $fieldName == "street"){
	$streetError = $errorMessage;
	}elseif(!eregi("^[a-z0-9'. ]{2,40}$", $_POST[street]) && $runExperssion == "run" && $fieldName == "street"){
		$streetError = $errorMessage;
		$streetSend = "false";
	}elseif(eregi("^[a-z0-9'. ]{2,40}$", $_POST[street]) && $runExperssion == "run" && $fieldName == "street"){
		$streetError = $approvedMessage;
		$streetSend = "true";
	};
// validate suburb
if($name == "" && $fieldName == "suburb"){
	$suburbError = $errorMessage;
	}elseif(!eregi("^[a-z'.0-9 ]{2,35}$", $_POST[suburb]) && $runExperssion == "run" && $fieldName == "suburb"){
		$suburbError = $errorMessage;
		$suburbSend = "false";
	}elseif(eregi("^[a-z'.0-9 ]{2,35}$", $_POST[suburb]) && $runExperssion == "run" && $fieldName == "suburb"){
		$suburbError = $approvedMessage;
		$suburbSend = "true";
	};
// validate postal code
if($name == "" && $fieldName == "postalCode"){
	$postalCodeError = $errorMessage;
	}elseif(!eregi("^[0-9]{2,6}$", $_POST[postalCode]) && $runExperssion == "run" && $fieldName == "postalCode"){
		$postalCodeError = $errorMessage;
		$postalCodeSend = "false";
	}elseif(eregi("^[0-9]{2,6}$", $_POST[postalCode]) && $runExperssion == "run" && $fieldName == "postalCode"){
		$postalCodeError = $approvedMessage;
		$postalCodeSend = "true";
	};
// validate town
if($name == "" && $fieldName == "town"){
	$townError = $errorMessage;
	}elseif(!eregi("^[a-z'. ]{2,35}$", $_POST[town]) && $runExperssion == "run" && $fieldName == "town"){
		$townError = $errorMessage;
		$townSend = "false";
	}elseif(eregi("^[a-z'. ]{2,35}$", $_POST[town]) && $runExperssion == "run" && $fieldName == "town"){
		$townError = $approvedMessage;
		$townSend = "true";
	};
// validate country
if($name == "0" && $fieldName == "country"){//1
	$countryError = $errorMessage;
	$countrySend = "false";
}elseif($name <> "0" && $fieldName == "country"){
	$countryError = $approvedMessage;
	$countrySend = "true";
}//1	

// validate message box
if($name == "" && $fieldName == "message"){
	$messageError = $errorMessage;
	$messageSend = "false";
	}elseif($name <> "" && $fieldName == "message"){
		$messageError = $approvedMessage;
		$messageSend = "true"; // Changed == to =
	};
// validate spam number
if($name == "" && $fieldName == "spam"){
	$spamError = $errorMessage;
	$spamSend = "false";
	}elseif($name <> $_POST[spamNumber]){
		$spamError = $errorMessage;
		$spamSend = "false";
	}elseif($name == $_POST[spamNumber]){
		$spamError = $approvedMessage;
		$spamSend = "true";
	};	
};//2 end funtion validate Name


// generated random number for spam check
$spamNumber = rand(1000,9999);

$approvedMark = "<img src='img/approvedMark.jpg' width='20' height='15' />";
$rejectMark = "<img src='img/rejectMark.jpg' width='15' height='15'/>";

validateNames($_POST[firstName], $rejectMark, $approvedMark, "firstName", "run");
validateNames($_POST[lastName], $rejectMark, $approvedMark, "lastName", "run");
validateNames($_POST[emailAddress], $rejectMark, $approvedMark, "emailAddress", "run");
validateNames($_POST[phoneNumber], $rejectMark, $approvedMark, "phoneNumber", "run");
validateNames($_POST[mobileNumber], $rejectMark, $approvedMark, "mobileNumber", "run");
validateNames($_POST[street], $rejectMark, $approvedMark, "street", "run");
validateNames($_POST[suburb], $rejectMark, $approvedMark, "suburb", "run");
validateNames($_POST[postalCode], $rejectMark, $approvedMark, "postalCode", "run");
validateNames($_POST[town], $rejectMark, $approvedMark, "town", "run");
validateNames($_POST[country],$rejectMark, $approvedMark, "country", "run");
validateNames($_POST[message], $rejectMark, $approvedMark, "message", "run");
validateNames($_POST[spam], $rejectMark, $approvedMark, "spam", "run");




function validateDate($fieldDay, $fieldMonth, $fieldYear, $rejectMessage, $approvedMessage){
global $dateError;
global $dateSend;


if($fieldDay == "0" || $fieldMonth =="0" || $fieldYear == "0"){//1
	$dateError = $rejectMessage;
	$dateSend = "false";
	return false;
};//1
if($fieldMonth == "4" || $fieldMonth == "6" || $fieldMonth == "9" || $fieldMonth == "11"){//1
	if($fieldDay > "30" ){//2
		$dateError = $rejectMessage;
		$dateSend = "false";
	}else{
		$dateError = $approvedMessage;
		$dateSend = "true";
	};//2
}else{
	$dateError = $approvedMessage;
	$dateSend = "true";
};//1
if($fieldMonth == "2" && $fieldDay > "28"){//3
	if($fieldYear % 4 == 0 && $fieldDay <= "29"){//4
		$dateError = $approvedMessage;
		$dateSend = "true";
		if($fieldYear % 100 == 0 && $fieldDay > "28"){//5
			$dateError = $rejectMessage;
			$dateSend = "false";
			if($fieldYear % 400 == 0 && $fieldDay <= "29"){//6
				$dateError = $approvedMessage;
				$dateSend = "true";
			}else{
				$dateError = $rejectMessage;
				$dateSend = "false";
			};//6
		}else{
			$dateError = $approvedMessage;
			$dateSend = "true";
		};//5
	}else{
		$dateError = $rejectMessage;
		$dateSend = "false";
	};//4
};//3 	 

};// function validateDate end

validateDate($_POST[day], $_POST[month], $_POST[year], $rejectMark, $approvedMark);

//echo "firstName ".$firstNameSend."</br>";
//echo "lastName ".$lastNameSend."</br>";
//echo "date ".$dateSend."</br>";
//echo "emailAddess ".$emailAddressSend."</br>";
//echo "phoneNumber ".$phoneNumberSend."</br>";
//echo "mobileNumber ".$mobileNumberSend."</br>";
//echo "street ".$streetSend."</br>";
//echo "suburb ".$suburbSend."</br>";
//echo "postalCoce ".$postalCodeSend."</br>";
//echo "town ".$townSend."</br>";
//echo "country ".$countrySend."</br>";
echo "message ".$messageSend."</br>";

if($firstNameSend == "true" && $lastNameSend == "true" && $emailAddressSend == "true" && $phoneNumberSend == "true" && $mobileNumberSend == "true" && $streetSend == "true" && $suburbSend == "true" && $postalCodeSend == "true" && $townSend == "true" && $countrySend == "true" && $messageSend == "true" && $dateSend == "true"){
//	$sendMail
echo "Message will Sendddd";
}else{
echo "Mesagge not sent!!!!!!!!!!!!!!!!";
};


};	


?>

 

Using the # Button

 

if you click the # button (aka code tags)

this will appear

without the spaces
then paste your code in
ie
[code ]
<?php
echo "this is PHP";
?>
and this is html
[/code ]

the result
[code]
<?php
echo "this is PHP";
?>
and this is html

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.