@ and @ thanks for the tips and help which got me going!
OK I've come across a few issues and new ideas when working on my project. I don't have room in the employment form to fit div's for the error messages. I did come up with using a span or div above the form which tells you how many errors there are and then highlight the input fields with red. I added this div class="message<?php echo $message; ?></div inside the body element of the HTML page to display the number of errors to the user. Will I have to create a value attribute for each html input element to get a red highlight? I've been looking online for ideas close to what I would like to do but all I found so far are people who are in the same boat as me. But now I'm not sure how to program that in I know Ill have to set up a CSS rule to get the color part which I already did. Also for some reason some of my code appears in the html page when I test it on a browser and not sure why. Any ideas why? I'm posting the code I came up with to see what I'm doing wrong. A lot of my code is commented out because I'm trying to work one idea at a time.
Code from the HTML form page (Main):
<?php
if(isset($_POST['submit'])) {
include('validateForm.php');
//Create post data to variables from each HTML form element
$FamilyName = trim($POST["FamilyName"]); <----- Not sure if trim good? I figured it was to get rid of white spaces....
$GivenName = trim($POST["GivenName"]);
$MiddleInitial = $POST["MiddleInitial"];
$curAddress = $POST["curAddress"];
$Municipality = $POST["Municipality"];
$Region = $POST["Region"];
$PostalCode = $POST["PostalCode"];
$phoneNumber = $POST["phoneNumber"];
$EmailAddress = $POST["EmailAddress"];
$legalYes = $POST["legalYes"];//radio button
$legalNo = $POST["legalNo"];//radio button
$applyPosition = $POST["applyPosition"];
$startDate = $POST["startDate"];
$fullTime = $POST["fullTime"];//radio button
$partTime = $POST["partTime"];//radio button
$idealHours = $POST["idealHours"];
$salaryRange = $POST["salaryRange"];
$overtimeYes = $POST["overtimeYes"];//radio button
$overtimeNo = $POST["overtimeNo"];//radio button
$skillsList = $POST["skillsList"];//textarea
$skillsComputer = $POST["skillsComputer"];//textarea
$hsName = $POST["hsName"];
$hsLocation = $POST["hsLocation"];
$hsPhoneNum = $POST["hsPhoneNum"];
$hsGradYes = $POST["hsGradYes"];//radio button
$hsGradNo = $POST["hsGradNo"];//radio button
$hsDegree = $POST["hsDegree"];
$collegeName = $POST["collegeName"];
$collegeLocation = $POST["collegeLocation"];
$collegePhoneNum = $POST["collegePhoneNum"];
$collegeGradYes = $POST["collegeGradYes"];//radio button
$collegeGradNo = $POST["collegeGradNo"];//radio button
$collegeDegree = $POST["collegeDegree"];
$techName = $POST["techName"];
$techLocation = $POST["techLocation"];
$techPhoneNum = $POST["techPhoneNum"];
$techGradYes = $POST["techGradYes"];//radio button
$techGradNo = $POST["techGradNo"];//radio button
$techDegree = $POST["techDegree"];
//There are four fieldsets for employment history
$OrganizationName = $POST["OrganizationName"];
$companyLocation = $POST["companyLocation"];
$Telephone = $POST["Telephone"];
$FormattedName = $POST["FormattedName"];
$leavingReason = $POST["leavingReason"];
$Title = $POST["Title"];
$EndDate = $POST["EndDate"];
$Compensation = $POST["Compensation"];
$SalaryOptions = $POST["SalaryOptions"];
$tempEmployYes = $POST["tempEmployYes"];//radio button
$tempEmplyDate = $POST["tempEmplyDate"];
$tempEmplyNo = $POST["tempEmplyNo"];//radio button
$unemployReason = $POST["unemployReason"];
$applicantName = $POST["applicantName"];
$applicantSignName = $POST["applicantSignName"];
$signDate = $POST["signDate"];
$errors = trim($POST["errors"]);
//start validating our form
$v = new validateForm();
$v->validateName($FamilyName, "FamilyName");
//Counts up all the errors <-------- Also may have to be changed
if (!$v-hasErrors()) {
//Sets the number of errors
$message = $v->errorNumMessage();
//Store the errors list in a variable
$errors = $v->displayErrors();
//get the individual error messages
$FamilyName = $v->getError("FamilyName");
}else{
return true;
}
}
exit;
?>
my PHP code (CODING PAGE):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
class validateForm {
//-------------------------------------------------------------------
// parameters
//-------------------------------------------------------------------
/**
Array to hold the errors
@access public
@var errors array
/
public $errors = array();
//------------------------------------------------------------------
// validation methods
//------------------------------------------------------------------
/**
Validates name fields
@access public
@
*/
public function validateName($FamilyName) {
if(strlen($FamilyName) <= 0 || strlen($FamilyName) >= 15 ) {
$this->setError($FamilyName, "Please enter a last name and it must be no longer than 15 characters"); <---- I believe this will have to be changed to something else if I want to use highlighted fields instead of text
}
else if(preg_match("/[a-zA-Z\-\., \']+$/")) {
$this->setError($FamilyName, "Last name must consist only of letters A-Z, ' and - "); <---- I believe this will have to be changed to something else if I want to use highlighted fields instead of text
}
}
/*function validateAddress($curAddress){
if(preg_match("/[a-zA-Z0-9 _-.,:']+$/") <= 0){
return true;
}
else
{
return false;
//error message to tell user either its wrong or wasn't entered
}
}
/function validateUSAZip($PostalCode){
if(preg_match("/([0-9]{5})(-[0-9]{4})?$/i") === 0){
return true;
}
else
{
return false;
//error message to tell user either its wrong or wasn't entered
}
}
/function validateEmail($EmailAddress){
if(preg_match("/\S+@[w\d.-]{2,}.[\w]{2,6}$/iU") === ""){
return true;
}
else
{
return false;
//error message to tell user either its wrong or wasn't entered
}
}
/function validatePhoneNum($phoneNumber){
if(trim($phoneNumber) === " "){
$errmsg = "Please enter a phone number.";
}
else if(!preg_match("/[0-9]{3}-[0-9]{3}-[0-9]{4}$/s")){
$errmsg = 'Please enter a valid phone number.';
return true;
}
}/
/$query = sprintf("INSERT INTO tbl (FamilyName, GivenName) Values (%s, %s)",
mysqli_real_escape_string($link, $FamilyName),
mysqli_real_escape_string($link, $GivenName)
);*/
//---------------------------------------------------------
// Error handling methods
//---------------------------------------------------------
/**
sets an error message for a form element
@access private
@ string $element - name of the form element
@ string $message - error message to be displayed
return void
/
private function setError($element, $errors){
$this->errors[$element] = $errors;
}//end logError
/**
returns the error of a single form element
@access public
@ string $elementName - name of the form element
@return string
/
public function getError($elementName){
if($this->errors[$elementName]){
return $this->errors[$elementName];
}
else
{
return false;
}
}//end getError
/**
displays the errors as an html un-ordered list <------ Not sure if this function needs to go or be changed if I want to display the errors as red highlighted boxes then actual text.
@access public
@return string: A html list of the forms errors
*/
public function displayErrors(){
$errorsList = "<ul class=\"errors\">\n";
foreach($this->errors as $value) {
$errorsList .= "<li>". $value . "</li>\n";
}
$errorsList .= "<\ul>\n";
return $errorsList;
}//end displayErrors
/**
returns whether the form has errors
@access public
@return boolean
*/
public function hasErrors() {
if(count($this->errors) >= 0) {
return true;
}
else
{
return false;
}
}//end hasErrors
/**
returns a string stating how many errors there were
@access public
@return void
*/
public function errorNumMessage() {
if(count($this->errors) > 1) {
$message = "There are " . count($this->errors) . " errors in the form!\n";
}
else
{
return true;
}
}//end errorNumMessage
}//end validateForm class
exit;
?>
</body>
</html>
When I've tried to test out my form it directly sent me to my index where the files are all stored? I've seen the error in the past but can't remember how to fix it I figured if I could get another pair of eyes on it you guys might be able to see something I didn't see. I greatly appreciate the help with helping a noob like me.
Overview of the HTML Form if needed or for comment reference:
[ATTACH]4593[/ATTACH]
employmentApp.txt