<?php
class Form
{
public $form;
function __construct
(array $form) {
$this->form = $form;
}
function clear($data)
{
foreach ($this->form as $key => $value) {
}
$data[$key] = abs((int
) $value); }
}
return $data;
}
function validate()
{
foreach ((array) $this->form as $key => $value) { if ($key == "name" && $key == "lastname") {
$error[$key] = "Введено слишком много символов, максимум можно вводить 200 символов";
}
}
if ($key == "email") {
if (preg_match("!^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$!", $value)) { } else {
$error[$key] = "Почта введена некорректно";
}
}
if ($key == "groupNumber") {
$error[$key] = "Номер группы введён неправильно";
}
}
if ($key == "point") {
if ($value > 1000) {
$error[$key] = "Количество баллов введено неправильно, так много быть не может";
}
}
if ($key == "yearBorn") {
(int) $value;
if ($value > 2010 or $value < 1900) {
$error[$key] = "Год введён неверно";
}
}
}
return $error;
}
}
}
$name = "Транквилий";
$lastname = "Konev";
$email = "konev@gmail.com";
$year = 19190;
$point = 100;
$groupNumber = "hh2eee3";
"name" => $name,
"lastname" => $lastname,
"email" => $email,
"yearBorn" => $year,
"groupNumber" => $groupNumber,
"point" => $point
);
$form = new Form($studentArray);
if ($studentArray = $form->clear($studentArray)) {
$formValidate = new Form($studentArray);
$result = $formValidate->validate();
if (count($result) == 0) { echo "Спасибо всё правильно введено";
} else {
foreach ($result as $key => $value) {
echo "Поле: $key - $value \n";
}
}
}
PD9waHAKY2xhc3MgRm9ybQp7CiAgICBwdWJsaWMgJGZvcm07CiAgICBmdW5jdGlvbiBfX2NvbnN0cnVjdChhcnJheSAkZm9ybSkKICAgIHsKICAgICAgICAkdGhpcy0+Zm9ybSA9ICRmb3JtOwogICAgfQogICAgZnVuY3Rpb24gY2xlYXIoJGRhdGEpCiAgICB7CiAgICAgICAgZm9yZWFjaCAoJHRoaXMtPmZvcm0gYXMgJGtleSA9PiAkdmFsdWUpIHsKICAgICAgICAgICAgaWYgKGlzX3N0cmluZygkdmFsdWUpKSB7CiAgICAgICAgICAgICAgICAkZGF0YVska2V5XSA9IHRyaW0oc3RyaXBfdGFncygkdmFsdWUpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoaXNfaW50KCR2YWx1ZSkpIHsKICAgICAgICAgICAgICAgICRkYXRhWyRrZXldID0gYWJzKChpbnQpICR2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuICRkYXRhOwogICAgfQogICAgZnVuY3Rpb24gdmFsaWRhdGUoKQogICAgewogICAgICAgIGZvcmVhY2ggKChhcnJheSkgJHRoaXMtPmZvcm0gYXMgJGtleSA9PiAkdmFsdWUpIHsKICAgICAgICAgICAgaWYgKCRrZXkgPT0gIm5hbWUiICYmICRrZXkgPT0gImxhc3RuYW1lIikgewogICAgICAgICAgICAgICAgaWYgKHN0cmxlbigkdmFsdWUpID4gMjAwKSB7CiAgICAgICAgICAgICAgICAgICAgJGVycm9yWyRrZXldID0gItCS0LLQtdC00LXQvdC+INGB0LvQuNGI0LrQvtC8INC80L3QvtCz0L4g0YHQuNC80LLQvtC70L7Qsiwg0LzQsNC60YHQuNC80YPQvCDQvNC+0LbQvdC+INCy0LLQvtC00LjRgtGMIDIwMCDRgdC40LzQstC+0LvQvtCyIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoJGtleSA9PSAiZW1haWwiKSB7CiAgICAgICAgICAgICAgICBpZiAocHJlZ19tYXRjaCgiIV4oW2EtejAtOV8tXStcLikqW2EtejAtOV8tXStAW2EtejAtOV8tXSsoXC5bYS16MC05Xy1dKykqXC5bYS16XXsyLDZ9JCEiLCAkdmFsdWUpKSB7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICRlcnJvclska2V5XSA9ICLQn9C+0YfRgtCwINCy0LLQtdC00LXQvdCwINC90LXQutC+0YDRgNC10LrRgtC90L4iOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICgka2V5ID09ICJncm91cE51bWJlciIpIHsKICAgICAgICAgICAgICAgIGlmIChzdHJsZW4oJHZhbHVlKSA+IDUgb3Igc3RybGVuKCR2YWx1ZSkgPCAyKSB7CiAgICAgICAgICAgICAgICAgICAgJGVycm9yWyRrZXldID0gItCd0L7QvNC10YAg0LPRgNGD0L/Qv9GLINCy0LLQtdC00ZHQvSDQvdC10L/RgNCw0LLQuNC70YzQvdC+IjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoJGtleSA9PSAicG9pbnQiKSB7CiAgICAgICAgICAgICAgICBpZiAoJHZhbHVlID4gMTAwMCkgewogICAgICAgICAgICAgICAgICAgICRlcnJvclska2V5XSA9ICLQmtC+0LvQuNGH0LXRgdGC0LLQviDQsdCw0LvQu9C+0LIg0LLQstC10LTQtdC90L4g0L3QtdC/0YDQsNCy0LjQu9GM0L3Qviwg0YLQsNC6INC80L3QvtCz0L4g0LHRi9GC0Ywg0L3QtSDQvNC+0LbQtdGCIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoJGtleSA9PSAieWVhckJvcm4iKSB7CiAgICAgICAgICAgICAgICAoaW50KSAkdmFsdWU7CiAgICAgICAgICAgICAgICBpZiAoJHZhbHVlID4gMjAxMCBvciAkdmFsdWUgPCAxOTAwKSB7CiAgICAgICAgICAgICAgICAgICAgJGVycm9yWyRrZXldID0gItCT0L7QtCDQstCy0LXQtNGR0L0g0L3QtdCy0LXRgNC90L4iOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChjb3VudCgkZXJyb3IpID4gMCkgewogICAgICAgICAgICByZXR1cm4gJGVycm9yOwogICAgICAgIH0KICAgIH0KfQokbmFtZSAgICAgICAgID0gItCi0YDQsNC90LrQstC40LvQuNC5IjsKJGxhc3RuYW1lICAgICA9ICJLb25ldiI7CiRlbWFpbCAgICAgICAgPSAia29uZXZAZ21haWwuY29tIjsKJHllYXIgICAgICAgICA9IDE5MTkwOwokcG9pbnQgICAgICAgID0gMTAwOwokZ3JvdXBOdW1iZXIgID0gImhoMmVlZTMiOwokc3R1ZGVudEFycmF5ID0gYXJyYXkoCiAgICAibmFtZSIgPT4gJG5hbWUsCiAgICAibGFzdG5hbWUiID0+ICRsYXN0bmFtZSwKICAgICJlbWFpbCIgPT4gJGVtYWlsLAogICAgInllYXJCb3JuIiA9PiAkeWVhciwKICAgICJncm91cE51bWJlciIgPT4gJGdyb3VwTnVtYmVyLAogICAgInBvaW50IiA9PiAkcG9pbnQKKTsKJGZvcm0gICAgICAgICA9IG5ldyBGb3JtKCRzdHVkZW50QXJyYXkpOwppZiAoJHN0dWRlbnRBcnJheSA9ICRmb3JtLT5jbGVhcigkc3R1ZGVudEFycmF5KSkgewogICAgJGZvcm1WYWxpZGF0ZSAgPSBuZXcgRm9ybSgkc3R1ZGVudEFycmF5KTsKICAgICRyZXN1bHQgPSAkZm9ybVZhbGlkYXRlLT52YWxpZGF0ZSgpOwogICAgaWYgKGNvdW50KCRyZXN1bHQpID09IDApIHsKICAgICAgICBlY2hvICLQodC/0LDRgdC40LHQviDQstGB0ZEg0L/RgNCw0LLQuNC70YzQvdC+INCy0LLQtdC00LXQvdC+IjsKICAgIH0gZWxzZSB7CiAgICAgICAgZm9yZWFjaCAoJHJlc3VsdCBhcyAka2V5ID0+ICR2YWx1ZSkgewogICAgICAgICAgICBlY2hvICLQn9C+0LvQtTogJGtleSAtICR2YWx1ZSBcbiI7CiAgICAgICAgfQogICAgfQp9Cg==