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

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

	if (empty($_POST['useremail'])) 
	{
		$data['errors']['useremail'] = 'Please enter your Email';
  }
	
	if (empty($_POST['subject'])) 
	{
		$data['errors']['subject'] = 'Please enter your Subject';
  }
	
	if (empty($_POST['usermessage'])) 
	{
		$data['errors']['usermessage'] = 'Please enter your Message';
  }	
			
	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';	
  }
}
?>