function validate_control($control)
{
// reference to the form submission method
global ${'_' . $this->form_properties['method']};
$method =& ${'_' . $this->form_properties['method']};
// at this point, we assume that the control is not valid
$valid = false;
// continue only if form was submitted
if (isset($method[$this->form_properties['identifier']]) && $method[$this->form_properties['identifier']] == $this->form_properties['name']) {
// at this point, we assume that the control is valid
$valid = true;
// reference to control
$control =& $this->controls[$control];
// treat "email" and "number" types as "text"
if (in_array($control->attributes['type'], array('email', 'number'))) {
$control->attributes['type'] = 'text';
}
// manage submitted value
$control->get_submitted_value();
// get some attributes of the control
$attribute = $control->get_attributes(array('name', 'id', 'type', 'value', 'multiple', 'format', 'disable_spam_filter', 'other'));
// if control doesn't have the SPAM filter disabled
if (!isset($attribute['disable_spam_filter']) || $attribute['disable_spam_filter'] !== true) {
// check to see if there is SPAM/INJECTION attempt by checking if the values in select boxes, radio buttons
// and checkboxes are in the list of allowable values, as set when initializing the controls
// check controls by type
switch ($attribute['type']) {
// if control is a select box
case 'select':
// if control was submitted
// (as there can also be no selections for a select box with the "multiple" attribute set, case in
// which there's no submission)
// (also, the isset() check is for when we "lock" controls)
if (isset($control->submitted_value) && $control->submitted_value) {
// flatten array (in case we have select groups)
$values = $this->_extract_values($control->attributes['options']);
// if the "other" attribute is set, then "other" is a valid option
if (isset($attribute['other'])) {
$values[] = 'other';
}
// we need to treat all values as strings
// or the in_array below will fail in strict mode
array_walk($values, create_function('&$value', '$value = (string)$value;'));
// if an array was submitted and there are values that are not in the list allowable values
if (is_array($control->submitted_value) && $control->submitted_value != array_intersect($control->submitted_value, $values)) {
// set a flag accordingly
$valid = false;
}
// if submitted value is not an array and submitted value is not in the list of allowable values
// we use strict mode or any string, when compared to 0, will be valid...
if (!is_array($control->submitted_value) && !in_array($control->submitted_value, $values, true)) {
// set a flag accordingly
$valid = false;
}
}
break;
// if control is a checkbox control or a radio button
// if control is a checkbox control or a radio button
case 'checkbox':
case 'radio':
// if control was submitted
if ($control->submitted_value) {
$values = array();
// iterate through all the form's controls
foreach ($this->controls as $element) {
// if control is of the same type and has the same name
if ($element->attributes['type'] == $attribute['type'] && $element->attributes['name'] == $attribute['name']) {
// add the control's value to the list of valid values
$values[] = $element->attributes['value'];
}
}
// if an array was submitted and there are values that are not in the list allowable values
if (is_array($control->submitted_value) && $control->submitted_value != array_intersect($control->submitted_value, $values)) {
// set a flag accordingly
$valid = false;
}
// if submitted value is not an array and submitted value is not in the list of allowable values
if (!is_array($control->submitted_value) && !in_array($control->submitted_value, $values)) {
// set a flag accordingly
$valid = false;
}
}
break;
}
// if spam attempt was detected
if (!$valid) {
// set the error message
$this->add_error('zf_error_spam', $this->form_properties['language']['spam_detected']);
// don't look further
return false;
}
}
// if
if (isset($control->submitted_value) && !empty($control->rules)) {
// we need to make sure that rules are in propper order, the order of priority being "dependencies",
// "required" and "upload"
// if the upload rule exists
if (isset($control->rules['upload'])) {
// remove it from wherever it is
$rule = array_splice($control->rules, array_search('upload', array_keys($control->rules)), 1, array());
// and make sure it's the first rule
$control->rules = array_merge($rule, $control->rules);
}
// if the "required" rule exists
if (isset($control->rules['required'])) {
// remove it from wherever it is
$rule = array_splice($control->rules, array_search('required', array_keys($control->rules)), 1, array());
// and make sure it's the first rule (it has to be checked prior to the "upload" rule)
$control->rules = array_merge($rule, $control->rules);
}
// if the "dependencies" rule exists
if (isset($control->rules['dependencies'])) {
// remove it from wherever it is
$rule = array_splice($control->rules, array_search('dependencies', array_keys($control->rules)), 1, array());
// and make sure it's the first rule (it has to be checked prior to the "required" and "upload" rules)
$control->rules = array_merge($rule, $control->rules);
}
// iterate through rules assigned to the control
foreach ($control->rules as $rule_name => $rule_attributes) {
// make sure the rule name is in lowercase
$rule_name = strtolower($rule_name);
// check the rule's name
switch ($rule_name) {
// if rule is "age"
case 'age':
if ($attribute['type'] == 'text' && $attribute['value'] != '' && isset($control->attributes['date']) && date('Y-m-d', strtotime($control->attributes['date'])) == $control->attributes['date']) {
// the allowed age interval
$min_age = $rule_attributes[0][0];
$max_age = $rule_attributes[0][1];
// compute age
$datetime1 = new DateTime();
$datetime2 = new DateTime($control->attributes['date']);
$interval = $datetime1->diff($datetime2);
$age = $interval->format('%y');
// if age is invalid
if (!(($min_age == 0 || $age >= $min_age) && ($max_age == 0 || $age <= $max_age))) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if rule is 'alphabet'
// if rule is 'alphabet'
case 'alphabet':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && !preg_match('/^[a-z' . preg_replace('/\\//', '\\/', preg_replace('/(?<!\\\\)\\-/', '\\-', preg_quote($rule_attributes[0]))) . ']+$/i', $attribute['value'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if rule is 'alphanumeric'
// if rule is 'alphanumeric'
case 'alphanumeric':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && !preg_match('/^[a-z0-9' . preg_replace('/\\//', '\\/', preg_replace('/(?<!\\\\)\\-/', '\\-', preg_quote($rule_attributes[0]))) . ']+$/i', $attribute['value'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if 'captcha'
// if 'captcha'
case 'captcha':
if ($attribute['type'] == 'text' && md5(md5(md5(strtolower($control->submitted_value)))) != ($this->form_properties['captcha_storage'] == 'session' ? @$_SESSION['captcha'] : @$_COOKIE['captcha'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if 'compare'
// if 'compare'
case 'compare':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && (!isset($method[$rule_attributes[0]]) || isset($method[$rule_attributes[0]]) && $control->submitted_value != $method[$rule_attributes[0]])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if 'dependencies'
// if 'dependencies'
case 'dependencies':
// if not all conditions are met, don't validate the control
if (!$this->_validate_dependencies($attribute['id'])) {
return true;
}
break;
// if 'convert'
// if 'convert'
case 'convert':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && $_FILES[$attribute['name']]['error'] == 0) {
// as conversions are done only when the form is valid
// for now we only save some data that will be processed if the form is valid
// (we're adding keys so that we don't have duplicate actions if validate_control method is called repeatedly)
$this->actions[$attribute['name'] . '_convert'] = array('_convert', $attribute['name'], 'extension' => $rule_attributes[0], 'quality' => $rule_attributes[1], 'preserve_original_file' => $rule_attributes[2], 'overwrite' => $rule_attributes[3], 'block' => $rule_attributes[4], 'message' => $rule_attributes[5]);
}
break;
// if 'custom' rule
// if 'custom' rule
case 'custom':
// custom rules are stored as an array
// iterate through the custom rules
foreach ($rule_attributes as $custom_rule_attributes) {
// if custom function exists
if (is_callable($custom_rule_attributes[0])) {
// the arguments that we are passing to the custom function are the control's
// submitted value and all other arguments passed when setting the custom rule
// except the first one which is the custom function's and the last two which are
// the error block name and the error message respectively
$arguments = array_merge(array($control->submitted_value), array_slice($custom_rule_attributes, 1, -2));
// run the custom function
// and if the function returns false
if (!call_user_func_array($custom_rule_attributes[0], $arguments)) {
// count the arguments passed when declaring the rules
$attributes_count = count($custom_rule_attributes);
// add error message to indicated error block
$this->add_error($custom_rule_attributes[$attributes_count - 2], $custom_rule_attributes[$attributes_count - 1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 3;
}
// if custom function doesn't exist, trigger an error message
} else {
_zebra_form_show_error('Function <strong>' . $custom_rule_attributes[0] . '()</strong> doesn\'t exist.', E_USER_ERROR);
}
}
break;
// if date
// if date
case 'date':
if ($attribute['type'] == 'text' && isset($attribute['format']) && $attribute['value'] != '') {
// if
if ($control->_init() && !($timestamp = $control->_is_format_valid($attribute['value'])) || $control->_is_disabled(date('Y', $timestamp), date('n', $timestamp), date('d', $timestamp))) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if "datecompare"
// if "datecompare"
case 'datecompare':
if ($attribute['type'] == 'text' && isset($attribute['format']) && $attribute['value'] != '' && isset($this->controls[$rule_attributes[0]]) && $this->controls[$rule_attributes[0]]->attributes['type'] == 'text' && $this->controls[$rule_attributes[0]]->attributes['format'] && $this->validate_control($this->controls[$rule_attributes[0]]->attributes['id'])) {
// we assume the control is invalid
$valid = false;
// compare the controls according to the comparison operator
switch ($rule_attributes[1]) {
case '>':
$valid = $control->attributes['date'] > $this->controls[$rule_attributes[0]]->attributes['date'];
break;
case '>=':
$valid = $control->attributes['date'] >= $this->controls[$rule_attributes[0]]->attributes['date'];
break;
case '<':
$valid = $control->attributes['date'] < $this->controls[$rule_attributes[0]]->attributes['date'];
break;
case '<=':
$valid = $control->attributes['date'] <= $this->controls[$rule_attributes[0]]->attributes['date'];
break;
}
// if invalid
if (!$valid) {
// add error message to indicated error block
$this->add_error($rule_attributes[2], $rule_attributes[3]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if rule is 'digits'
// if rule is 'digits'
case 'digits':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && !preg_match('/^[0-9' . preg_replace('/\\//', '\\/', preg_replace('/(?<!\\\\)\\-/', '\\-', preg_quote($rule_attributes[0]))) . ']+$/', $attribute['value'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if "email"
// if "email"
case 'email':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && (preg_match('/\\.{2,}/', $attribute['value']) || strlen($attribute['value']) > 254 || !preg_match('/^[^\\.][a-z0-9_\\-\\+\\~\\^\\{\\}\\.]{1,64}@[a-z0-9_\\-\\+\\~\\^\\{\\}\\.]{1,255}\\.[a-z0-9]{2,}$/i', $attribute['value']))) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if "list of emails"
// if "list of emails"
case 'emails':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '') {
// convert string to an array of addresses
$addresses = explode(',', $attribute['value']);
// iterate through the addresses
foreach ($addresses as $address) {
// not a valid email address
if (!preg_match('/^([a-zA-Z0-9_\\-\\+\\~\\^\\{\\}]+[\\.]?)+@{1}([a-zA-Z0-9_\\-\\+\\~\\^\\{\\}]+[\\.]?)+\\.[A-Za-z0-9]{2,}$/', trim($address))) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 3;
}
}
}
break;
// if "filesize"
// if "filesize"
case 'filesize':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && ($_FILES[$attribute['name']]['size'] > $rule_attributes[0] || $_FILES[$attribute['name']]['error'] == 1 || $_FILES[$attribute['name']]['error'] == 2)) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if "filetype"
// if "filetype"
case 'filetype':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && $_FILES[$attribute['name']]['error'] == 0) {
// if "finfo_open" function exists (from PHP 5.3.0)
if (function_exists('finfo_open')) {
// determine the "true" mime type of the uploaded file
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES[$attribute['name']]['tmp_name']);
finfo_close($finfo);
// otherwise, rely on the information returned by $_FILES which uses the file's
// extension to determine the uploaded file's mime type and is therefore unreliable
} else {
$mime = $_FILES[$attribute['name']]['type'];
}
// get the allowed file types
$allowed_file_types = array_map(create_function('$value', 'return trim($value);'), explode(',', $rule_attributes[0]));
// this will contain an array of file types that match for the currently uploaded file's
// mime type
$matching_file_types = array();
// load mime file types
$this->_load_mime_types();
// iterate through the known mime types
foreach ($this->form_properties['mimes'] as $extension => $type) {
// if
if (is_array($type) && in_array($mime, $type) || !is_array($type) && $type == $mime) {
$matching_file_types[] = $extension;
}
}
// is the file allowed?
$matches = array_intersect($matching_file_types, $allowed_file_types);
// if file is not allowed
if (empty($matches)) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if rule is 'float'
// if rule is 'float'
case 'float':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && (trim($attribute['value']) == '.' || trim($attribute['value']) == '-' || preg_match_all('/\\-/', $attribute['value'], $matches) > 1 || preg_match_all('/\\./', $attribute['value'], $matches) > 1 || !preg_match('/^[0-9\\-\\.' . preg_replace('/\\//', '\\/', preg_replace('/(?<!\\\\)\\-/', '\\-', preg_quote($rule_attributes[0]))) . ']+$/', $attribute['value']) || strpos($attribute['value'], '-') !== false && strpos($attribute['value'], '-') > 0)) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if "image"
// if "image"
case 'image':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && $_FILES[$attribute['name']]['error'] == 0) {
// get some information about the file
list($width, $height, $type, $attr) = @getimagesize($_FILES[$attribute['name']]['tmp_name']);
// if file is not an image or image is not gif, png or jpeg
if ($type === false || $type < 1 || $type > 3) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if "length"
// if "length"
case 'length':
// the rule will be considered as not obeyed when
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && (strlen(utf8_decode(html_entity_decode($attribute['value']))) < $rule_attributes[0] || $rule_attributes[1] > 0 && strlen(utf8_decode(html_entity_decode($attribute['value']))) > $rule_attributes[1])) {
// add error message to indicated error block
$this->add_error($rule_attributes[2], $rule_attributes[3]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if rule is 'number'
// if rule is 'number'
case 'number':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && (trim($attribute['value']) == '-' || preg_match_all('/\\-/', $attribute['value'], $matches) > 1 || !preg_match('/^[0-9\\-' . preg_replace('/\\//', '\\/', preg_replace('/(?<!\\\\)\\-/', '\\-', preg_quote($rule_attributes[0]))) . ']+$/', $attribute['value']) || strpos($attribute['value'], '-') !== false && strpos($attribute['value'], '-') > 0)) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if rule is "range"
// if rule is "range"
case 'range':
if ($attribute['type'] == 'text' && $attribute['value'] != '') {
// get the allowed min and max
$min = $rule_attributes[0][0];
$max = $rule_attributes[0][1];
// make sure the value is a number
$value = (double) $attribute['value'];
// if
if ($value != $attribute['value'] || !(($min == 0 || $value >= $min) && ($max == 0 || $value <= $max))) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if "regexp"
// if "regexp"
case 'regexp':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && !preg_match('/' . $rule_attributes[0] . '/', $attribute['value'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
// if "required"
// if "required"
case 'required':
// if it's a drop-down that is part of a time control
if ($attribute['type'] == 'time') {
// if invalid format specified, revert to the default "hm"
if (preg_match('/^[hmsg]+$/i', $attribute['format']) == 0 || strlen(preg_replace('/([a-z]{2,})/i', '$1', $attribute['format'])) != strlen($attribute['format'])) {
$attribute['format'] = 'hm';
}
$regexp = '';
// build the regular expression for validating the time
for ($i = 0; $i < strlen($attribute['format']); $i++) {
// for each characher in the format we use a particular regular expression
switch (strtolower(substr($attribute['format'], $i, 1))) {
case 'h':
// if 12 hour format is used use this expression...
if (strpos(strtolower($attribute['format']), 'g')) {
$regexp .= '0[1-9]|1[012]';
} else {
$regexp .= '([0-1][0-9]|2[0-3])';
}
break;
case 'm':
case 's':
// regular expression for validating minutes and seconds
$regexp .= '[0-5][0-9]';
break;
case 'g':
// validate am/pm
$regexp .= '(am|pm)';
break;
}
}
// if time does not validate
if (preg_match('/' . $regexp . '/i', str_replace(array(':', ' '), '', $attribute['value'])) == 0) {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
// for other controls
} else {
// if control is 'select'
if ($attribute['type'] == 'select') {
// as of PHP 5.3, array_shift required the argument to be a variable and not the result
// of a function so we need this intermediary step
$notSelectedIndex = array_keys($control->attributes['options']);
// get the index which when selected indicated that 'nothing is selected'
$notSelectedIndex = array_shift($notSelectedIndex);
}
// the rule will be considered as not obeyed when
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && trim($attribute['value']) == '' || $attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && trim($_FILES[$attribute['name']]['name']) == '' || ($attribute['type'] == 'checkbox' || $attribute['type'] == 'radio') && $control->submitted_value === false || $attribute['type'] == 'select' && isset($attribute['multiple']) && $control->submitted_value === false || $attribute['type'] == 'select' && !isset($attribute['multiple']) && (is_array($control->submitted_value) || strcmp($control->submitted_value, $notSelectedIndex) == 0) || $attribute['type'] == 'select' && !isset($attribute['multiple']) && $control->submitted_value == 'other' && trim($method[$attribute['name'] . $this->form_properties['other_suffix']]) == '') {
// add error message to indicated error block
$this->add_error($rule_attributes[0], $rule_attributes[1]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
}
break;
// if 'resize'
// if 'resize'
case 'resize':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && $_FILES[$attribute['name']]['error'] == 0) {
// as of PHP 5.3, array_shift required the argument to be a variable and not the result
// of a function so we need this intermediary step
$tmp = array_values($rule_attributes);
// if not multiple resize calls
// make it look like multiple resize call
if (!is_array(array_shift($tmp))) {
$rule_attributes = array($rule_attributes);
}
// iterate through the resize calls
foreach ($rule_attributes as $index => $rule_attribute) {
// as resizes are done only when the form is valid and after the file has been
// uploaded, for now we only save some data that will be processed if the form is valid
// (we're adding keys so that we don't have duplicate actions if validate_control method is called repeatedly)
$this->actions[$attribute['name'] . '_resize_' . $index] = array('_resize', $attribute['name'], $rule_attribute[0], $rule_attribute[1], $rule_attribute[2], $rule_attribute[3], $rule_attribute[4], $rule_attribute[5], $rule_attribute[6], $rule_attribute[7], 'block' => $rule_attribute[8], 'message' => $rule_attribute[9]);
}
}
break;
// if 'upload'
// if 'upload'
case 'upload':
if ($attribute['type'] == 'file' && isset($_FILES[$attribute['name']]) && $_FILES[$attribute['name']]['error'] == 0) {
// as uploads are done only when the form is valid
// for now we only save some data that will be processed if the form is valid
// (we're adding keys so that we don't have duplicate actions if validate_control method is called repeatedly)
$this->actions[$attribute['name'] . '_upload'] = array('_upload', $attribute['name'], $rule_attributes[0], $rule_attributes[1], 'block' => $rule_attributes[2], 'message' => $rule_attributes[3]);
}
break;
// if "url"
// if "url"
case 'url':
if (($attribute['type'] == 'password' || $attribute['type'] == 'text' || $attribute['type'] == 'textarea') && $attribute['value'] != '' && !preg_match('/^(https?\\:\\/\\/)' . ($rule_attributes[0] === true ? '' : '?') . '[^\\s\\.]+\\..{2,}/i', $attribute['value'])) {
// add error message to indicated error block
$this->add_error($rule_attributes[1], $rule_attributes[2]);
// the control does not validate
$valid = false;
// no further checking needs to be done for the control, making sure that only one
// error message is displayed at a time for each erroneous control
break 2;
}
break;
}
}
}
}
return $valid;
}