<?php 
if(isset($_POST)) 
{
	$data['errors'] = array();

	if (empty($_POST['userfirstname'])) 
	{
		$data['errors']['userfirstname'] = 'Please enter your First Name';
	}
	elseif(preg_match('/\\d/', $_POST['userfirstname']) == 1) 
	{
		$data['errors']['userfirstname'] = 'Please enter only Alphabets';
	}

	if (empty($_POST['userlastname'])) 
	{
		$data['errors']['userlastname'] = 'Please enter your Last Name';
	}
	elseif(preg_match('/\\d/', $_POST['userlastname']) == 1) 
	{
		$data['errors']['userlastname'] = 'Please enter only Alphabets';
	}

	if (empty($_POST['useremail'])) 
	{
		$data['errors']['useremail'] = 'Please enter your Email';
  }
	
	if (empty($_POST['phone'])) 
	{
		$data['errors']['phone'] = 'Please enter your Phone';
	}
	
	if (empty($_POST['userdrname'])) 
	{
		$data['errors']['userdrname'] = 'Please enter Dr. Name';
	}
	elseif(preg_match('/\\d/', $_POST['userdrname']) == 1) 
	{
		$data['errors']['userdrname'] = 'Please enter only Alphabets';
	}

	if (empty($_POST['userspeciality'])) 
	{
		$data['errors']['userspeciality'] = 'Please enter Speciality';
	}
	elseif(preg_match('/\\d/', $_POST['userspeciality']) == 1) 
	{
		$data['errors']['userspeciality'] = 'Please enter only Alphabets';
	}
	
	if(count($data['errors']) > 0) 
	{
	  //This is for ajax requests:
		if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
		{
    	echo json_encode($data['errors']);
			return false;
      exit;
    }
		
		//This is when Javascript is turned off:
    echo "<ul>";
		foreach($data['errors'] as $key => $value)	
		{
	  	echo "<li>" . $value . "</li>";
    }
    echo "</ul>";
		return false;
		exit;
	}
	else
	{
		echo 'true';	
  }
}
?>