parent
ca78aca8cb
commit
0ef6c6df4e
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Silex\Validation;
|
||||
|
||||
final class NewsValidation
|
||||
{
|
||||
public static function isValidNews(array &$post, array &$errors): bool
|
||||
{
|
||||
if (empty($post['title'])) {
|
||||
$errors[] = 'Empty title';
|
||||
}
|
||||
if (empty($post['content'])) {
|
||||
$errors[] = 'Empty message';
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
return false;
|
||||
}
|
||||
if (strlen($post['title']) > 60) {
|
||||
$errors[] = 'Title too long';
|
||||
}
|
||||
$post['title'] = htmlspecialchars($post['title']);
|
||||
$post['content'] = htmlspecialchars($post['content']);
|
||||
return empty($errors);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue