Hier heb ik nog een code waar ik problemen mee heb.
Dit is een class voor een ander validation script.
een hele mooie en opnieuw bruikbare code.. maar helaas met een fout erin en ik kan er zelfs niet achterkomen wat het probleem is.
De foutmelding die op het scherm te staan komt is als volgt: Parse error: syntax error, unexpected '$rule_line' (T_VARIABLE) on line 37
Weet iemand hoe dit opgelost moet worden?
<?php
class Validation
{
protected $POST = array();
public $rules = array();
public $fields = array();
public $errors = array();
public function __construct($post)
{
$this->POST = $post;
}
public function set_rule($field, $label, $rules = NULL)
{
$this->rules[$field] = $rules;
$this->fields[$field] = $label;
}
private function _split_rules($rules)
{
return explode("|", $rules);
}
public function run()
{
foreach($this->rules as $field => $rule)
{
$rule_lines = $this->_split_rules($rule);
}
foreach ($rule_lines as $rule_line)
{
if (is_callable($this->_$rule_line)) //LINE37
{
$this->_$rule_line($field);
}
}
return true;
}
private function _error_message($field , $message)
{
$this->errors[$field] = $message;
}
/**
RULES
**/
private function preg($rule)
{
}
private function _required($input)
{
$keys = array_keys($this->POST);
if(!in_array($input, $keys))
{
return FALSE;
}
}
private function _valid_email($field)
{
return (preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/', $this->POST[$field]));
}
private function _valid_phone($field)
{
return (preg_match('/^[0-9]+$/', $this->POST[$field]));
}
}
Alvast vriendelijk bedankt!
1.072 views