function captcha() { // Validate CAPTCHA verification code; if any F3::input('captcha', function ($value) { if (!F3::exists('message') && F3::exists('SESSION.captcha')) { $captcha = F3::get('SESSION.captcha'); if (empty($value)) { F3::set('message', 'Verification code required'); } elseif (strlen($value) > strlen($captcha)) { F3::set('message', 'Verification code is too long'); } elseif (strtolower($value) != $captcha) { F3::set('message', 'Invalid verification code'); } } }); }
function soyad() { // Validate blog soyad F3::input('soyad', function ($value) { if (!F3::exists('message')) { if (empty($value)) { F3::set('message', 'Soyad should not be blank'); } elseif (strlen($value) > 127) { F3::set('message', 'Soyad is too long'); } elseif (strlen($value) < 3) { F3::set('message', 'Soyad is too short'); } } // Do post-processing of soyad here F3::set('REQUEST.soyad', ucfirst($value)); }); }
} }); // tc numara geçerli olmalı F3::input($alan = 'tc', function ($value) use($alan) { $ne = "Tc No"; if ($hata = denetle($value, array('dolu' => array(true, "{$ne} boş bırakılamaz"), 'esit' => array(11, "{$ne} 11 haneli olmalıdır"), 'tamsayi' => array(true, "{$ne} sadece rakam içermeli"), 'ozel' => array(function ($value) { return !is_tc($value); }, "Geçerli bir {$ne} değil")))) { F3::set('error', $hata); return; } }); F3::input($alan = 'kizliksoyad', function ($value) use($alan) { $ne = "Kızlık Soyadı"; if ($hata = denetle($value, array('dolu' => array(true, "{$ne} boş bırakılamaz")))) { F3::set('error', $hata); return; } }); if (!F3::exists('error')) { $tc = F3::get('REQUEST.tc'); $kizliksoyad = F3::get('REQUEST.kizliksoyad'); $kul = new Axon('kul'); $kul->load("tc={$tc}"); if (!$kul->dry() && streq_turkish($kul->kizliksoyad, $kizliksoyad)) { // tc no'yu oturuma gömelim ve oradan alalım F3::set('SESSION.sorgutc', $tc); F3::set('SESSION.sorgukizliksoyad', $kizliksoyad); return F3::call(':sorguok'); } F3::set('error', "Girdiğiniz bilgilere uygun bir kayıt bulunamadı. Lütfen verdiğiniz bilgileri kontrol edin.");
function userpassword() { // Validate userpassword F3::input('userpassword', function ($value) { if (!F3::exists('message')) { if (empty($value)) { F3::set('message', 'Parola should not be blank'); } elseif (strlen($value) > 127) { F3::set('message', 'Parola is too long'); } elseif (strlen($value) < 3) { F3::set('message', 'Parola is too short'); } } // Do post-processing of userpassword here F3::set('REQUEST.userpassword', ucfirst($value)); }); }
function validator() { $this->set('title', 'User Input'); $this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text')); $this->route('POST /form', function () { F3::input('field1', 'nonexistent'); }); $this->set('QUIET', TRUE); $this->mock('POST /form'); $this->run(); $this->expect(!is_null($this->get('ERROR')) && $this->get('ERROR.code') === 500, 'HTTP 500 expected - form field handler is invalid', 'No HTTP 500 triggered'); $this->set('QUIET', FALSE); $this->clear('ERROR'); $this->route('POST /form', function () { F3::input('field', function ($value) { F3::expect($value == 'alert(\'hello\');', 'HTML tags removed (attempt to insert Javascript)', 'HTML tags were not removed: ' . $value); }); }); $this->mock('POST /form', array('field' => '<script>alert(\'hello\');</script>')); $this->run(); $this->clear('ROUTES'); $this->expect($_POST['field'] == 'alert(\'hello\');' && $_POST['field'] == 'alert(\'hello\');', 'Framework sanitizes underlying $_POST and $_POST variables', 'Framework didn\'t sanitize $_POST/$_POST: ' . $_POST['field']); $this->set('POST', array('field' => '<p><b>hello</b> world</p>')); $this->input('field', function ($value) { F3::expect($value == '<p>hello world</p>', 'HTML tags allowed but not converted to HTML entities' . '<br/>Note: application is responsible for ' . 'HTML decoding', 'HTML tags not converted/blocked by framework: ' . $value); }, 'p'); $this->set('POST', array('field' => 'Adam & Eve')); $this->input('field', function ($value) { F3::expect($value == 'Adam & Eve', 'Ampersand preserved', 'Ampersand converted to HTML entity!'); }); $this->set('POST', array('field' => '©')); $this->input('field', function ($value) { F3::expect($value == '©', 'No duplicate encoding of HTML entity: ' . $value, 'Double-encoding of HTML entity: ' . $value); }); $this->set('POST', array('field' => 'hello "world"')); $this->input('field', function ($value) { F3::expect($value == 'hello "world"', 'Double-quotes preserved: ' . $value, 'Double-quotes not handled properly: ' . $value); }); $this->expect(Data::validEmail('!def!xyz%abc@example.com'), 'Valid e-mail address: !def!xyz%abc@example.com', 'Framework flagged !def!xyz%abc@example.com invalid!'); $this->expect(Data::validEmail('"Abc@def"@example.com'), 'Valid e-mail address: "Abc@def"@example.com', 'Framework flagged "Abc@def"@example.com invalid!'); $this->expect(!Data::validEmail('"Abc@def"@example.com', TRUE), 'Invalid e-mail address: "Abc@def"@example.com (MX record verified)', 'Framework flagged "Abc@def"@example.com valid!'); $this->expect(!Data::validEmail('Abc@def@example.com'), 'Invalid e-mail address: Abc@def@example.com', 'Framework flagged Abc@def@example.com valid!'); $this->expect(Data::validEmail('*****@*****.**'), 'Valid e-mail address: a@b.com (MX record not verified)', 'Framework flagged a@b.com invalid!'); $this->expect(!Data::validEmail('*****@*****.**', TRUE), 'Invalid e-mail address: a@b.com (MX record verified)', 'Framework flagged a@b.com valid!'); $this->expect(Data::validURL('http://www.google.com'), 'Valid URL: http://www.google.com', 'Framework flagged http://www.google.com invalid!'); $this->expect(Data::validURL('http://www.yahoo.com/'), 'Valid URL: http://www.yahoo.com/', 'Framework flagged http://www.yahoo.com/ invalid!'); $this->expect(Data::validURL('http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient'), 'Valid URL: ' . 'http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient', 'Framework flagged ' . 'http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient ' . 'invalid!'); $this->expect(Data::validURL('http://www.yahoo.com?http%3A%2F%2Fwww.yahoo.com'), 'Valid URL: http://www.yahoo.com?http%3A%2F%2Fwww.yahoo.com', 'Framework flagged ' . 'http://www.yahoo.com?http%3A%2F%2Fwww.yahoo.com invalid!'); echo $this->render('basic/results.htm'); }
if ($hata = denetle(strtolower($value), array('dolu' => array(true, "{$ne} boş bırakılamaz"), 'enaz' => array(strlen($captcha), "{$ne} çok kısa"), 'degeri' => array(strtolower($captcha), "Yanlış {$ne}")))) { F3::set('error', $hata); return; } }); // ad ve soyad şart foreach (array('ad', 'soyad') as $alan) { F3::input($alan, function ($value) use($alan) { $ne = ucfirst($alan); if ($hata = denetle($value, array('dolu' => array(true, "{$ne} boş bırakılamaz"), 'enaz' => array(2, "{$ne} çok kısa"), 'enfazla' => array(127, "{$ne} çok uzun")))) { F3::set('error', $hata); return; } F3::set("REQUEST.{$alan}", ucfirst($value)); }); } // tc numara geçerli olmalı F3::input($alan = 'tc', function ($value) use($alan) { $ne = "Tc No"; if ($hata = denetle($value, array('dolu' => array(true, "{$ne} boş bırakılamaz"), 'esit' => array(11, "{$ne} 11 haneli olmalıdır"), 'tamsayi' => array(true, "{$ne} sadece rakam içermeli"), 'ozel' => array(function ($value) { return !is_tc($value); }, "Geçerli bir {$ne} değil")))) { F3::set('error', $hata); return; } $kul = new Axon('kul'); if ($kul->found("tc={$value}")) { F3::set('error', "{$ne} {$value} daha önceden eklendi"); return; } });