PHP error array

I’m trying to create an array so that any errors encountered can be output at the bottom of a form. I am having two problems though. One is that I’m fairly certain the php side of the code is ignoring my “_submit_check” hidden value. The second (more important) issue is that the error array is not aggregating OR outputting when invalid form data is entered! :frowning:

Could anyone please look over this script and let me know of any errors? (Be tough, this is my first PHP project and I learn by example)

<form method="post" action="search.php?find" id="searchform">
<input type="submit" name="add" value="Add an employee">
date_default_timezone_set('America/New_York'); //set for date functions

function realdate($date) {
	if(preg_match("/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/", $_POST['hiredate2'])){
	$dateparts = explode("-", $date);
	if(!checkdate($mm, $dd, $yyyy)) {
		$errors[]="$date is an invalid date. /r/n";
	else {
} else {
	$errors[]="$date must be formatted as MM-DD-YYYY.";

echo "<b><u>Employee Information</u></b> <br><br>
<form name=\"jump\">
<select name=\"menu\" onChange=\"[].value;\" value=\"GO\">
<option value=\"\">Select a Department</option>
<option value=\"?addadmin\">Administration</option>

if(isset($_POST['_submit_check'])){ //$_POST['_submit_check'] is a hidden field, makes redisplay possible
   if($form_errors = validate_form()){
   } else {
} else {

function show_form($errors = '') {
print "<b><u>Employee Information</u></b><form method=\"post\" action=\"search.php?addadmin\" id=\"editform\"> <ul>
		<table border=\"0\" width=\"550\">
include 'basicinfo.php';
		<td>Hire date:</td>
		<td><input type=\"text\" name=\"hiredate2\"> (mm-dd-yyyy)</td>
		<td>Orientation completed?</td>
		<td><input type=\"checkbox\" name=\"orientation2\" value=\"Yes\" /></td>
include 'basictrainings.php';
print "</table></ul> 
		<input type=\"submit\" name=\"submit2\" value=\"Submit\">
		<input type=\"hidden\" name=\"_submit_check\" value=\"1\">
		<input type=\"button\" name=\"Cancel\" value=\"Cancel\" onclick=\"window.location = 'search.php' \" />
//output any errors
if ($errors){
print 'Please correct these errors: <ul><li>';
print implode('</li><li>', $errors);
print '</li></ul>';

function validate_form(){
	if(!preg_match("/^[A-Z|a-z]+$/", $_POST['lastname2'])){
		$errors[]= "You must enter a valid last name.";
	if(!preg_match("/^[A-Z|a-z]+$/", $_POST['firstname2'])){
		$errors[]= "You must enter a valid first name.";

function process_form(){

if (isset($_POST['orientation2'])) { // checkbox has been checked
} else {


include 'db.php'; //connect to the database
include 'insert.php';


echo "<p>Entry created for " . $lastname2 . ", " . $firstname2 . "</p>"; 
echo "Tried to pass:" . $sql . ".";

I have determined this is not an array error anymore. This is a more fundamental error where the form is not being validated properly. I’m pretty sure the <input type=\"hidden\" name=\"_submit_check\" value=\"1\"> line is not being submitted, thereby never triggering the validate_form() function. I’m using PHP 5.3.

Is anyone else having this issue??

Sponsor our Newsletter | Privacy Policy | Terms of Service