Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 73 additions & 68 deletions code/NetefxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,83 @@
* @author zauberfisch
*/

class NetefxValidator extends Validator {

protected $rules;
protected $javascriptValidationHandler = 'none';
class NetefxValidator extends Validator
{

protected $rules;
protected $javascriptValidationHandler = 'none';

/**
* @return array
*/
public function getRules() {
return $this->rules;
}

/**
* if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array
* @param array|mixed $items
*/
public function setRules($items = null) {
$this->rules = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items;
}

/**
* if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array
* @param array|mixed $items
*/
public function __construct() {
$this->setRules(func_get_args());
parent::__construct();

}
/**
* @return array
*/
public function getRules()
{
return $this->rules;
}

/**
* if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array
* @param array|mixed $items
*/
public function setRules($items = null)
{
$this->rules = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items;
}

/**
* if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array, otherwise use the passed array
* @param array|mixed $items
*/
public function __construct()
{
$this->setRules(func_get_args());
parent::__construct();
}


/**
* javascript not implemented yet
* @return string
*/
function javascript() {
$js = "";
return $js;
}

/**
* javascript not implemented yet
* @return string
*/
public function javascript()
{
$js = "";
return $js;
}

/**
* calls validate() on all fields and rules
* @return boolean
*/
function php($data) {
$valid = true;
/**
* calls validate() on all fields and rules
* @return boolean
*/
public function php($data)
{
$valid = true;

$fields = $this->form->Fields();
foreach($fields as $field) {
$valid = ($field->validate($this) && $valid);
}
if($this->rules) {
foreach($this->rules as $rule) {

if (!$rule->validate($data)) {
$errorMessage = $rule->getErrorMessage();
$errorMessageType = $rule->getErrorMessageType();
$fieldName = $rule->getField();

$this->validationError(
$fieldName,
$errorMessage,
$errorMessageType
);
$valid = false;
}
}
}
$fields = $this->form->Fields();
foreach ($fields as $field) {
$valid = ($field->validate($this) && $valid);
}
if ($this->rules) {
foreach ($this->rules as $rule) {
if (!$rule->validate($data)) {
$errorMessage = $rule->getErrorMessage();
$errorMessageType = $rule->getErrorMessageType();
$fieldName = $rule->getField();

$this->validationError(
$fieldName,
$errorMessage,
$errorMessageType
);
$valid = false;
}
}
}

if (!$valid) Session::set("NetefxValidatorError",true);
if (!$valid) {
Session::set("NetefxValidatorError", true);
}

return $valid;
}

return $valid;
}
}
Loading