PHP Filters
Hej jag har svårt att få någon resultat på min kod. Skulle behöva någon se över den o saga vad som är fel, det visas bara blankt
Koden I första filen:
<?php
class validator
{
protected $_inputType;
protected $_submitted;
protected $_required;
protected $_filterArgs;
protected $_filtered;
protected $_missing;
protected $_errors;
protected $_booleans;
public function __construct($required = array(), $inputType = 'post')
{
if (!function_exists('filter_list'))
{
throw new Exception('The Pos_Validator class requires the Filter Functions in >= PHP 5.2 or PECL.');
}
if (!is_null($required) && !is_array($required))
{
throw new Exception('The names of required fields must be an array, even if only one field is required.');
}
$this->_required = $required;
$this->setInputType($inputType);
if ($this->_required)
{
$this->checkRequired();
}
$this->_filterArgs = array();
$this->_errors = array();
$this->_booleans = array();
}
protected function setInputType($type)
{
switch (strtolower($type))
{
case 'post': $this->_inputType = INPUT_POST;
$this->_submitted = $_POST;
break;
case 'get': $this->_inputType = INPUT_GET;
$this->_submitted = $_GET;
break;
default:
throw new Exception('Invalid input type. Valid types are "post" and "get".');
}
}
protected function checkRequired()
{
$OK = array();
foreach ($this->_submitted as $name => $value)
{
$value = is_array($value) ? $value : trim($value);
if (!empty($value))
{
$OK[] = $name;
}
}
$this->_missing = array_diff($this->_required, $OK);
print_r($this->_missing);
}
}
?>
Andra filen som koden körs ifrån:
<?php if (filter_has_var(INPUT_POST, 'send'))
{
require_once 'validator.php';
$required = array('name', 'email', 'comments');
$val = new validator($required);
$val->checkTextLength('name', 3);
$val->removeTags('name');
$val->isEmail('email');
$val->checkTextLength('comments', 10, 500);
$val->useEntities('comments');
echo '<pre>';
print_r($val->_filterArgs); print_r($val->_errors);
echo '</pre>';
}
?>
Beror felet på att jag inte har någon 'Post' och 'GET' inputs där användaren skriver in?
Jag får varkel felkod eller något utskrivet, bara blankt
Tacksam för hjälp