Skip to content

Commit

Permalink
#2 必須バリデーションの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
YutaroYutaro committed Dec 13, 2018
1 parent e6b5000 commit ed9aebc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/php/Class/BbsValidation.php
Expand Up @@ -21,7 +21,8 @@ public function TitleValidation($title)
{
$errors = [];

if (!$this->MaxSize($title, 50)) $errors['title_length'] = 'タイトルは50文字以内で入力してください.';
if ($this->MaxSize($title, 50)) $errors['title_length'] = 'タイトルは50文字以内で入力してください.';
if ($this->Required($title)) $errors['title_required'] = 'タイトルを入力してください.';

return $errors;
}
Expand All @@ -30,7 +31,8 @@ public function CommentValidation($comment)
{
$errors = [];

if (!$this->MaxSize($comment, 100)) $errors['comment_length'] = 'コメントは100文字以内で入力してください.';
if ($this->MaxSize($comment, 100)) $errors['comment_length'] = 'コメントは100文字以内で入力してください.';
if ($this->Required($comment)) $errors['comment_required'] = 'コメントを入力してください.';

return $errors;
}
Expand Down
6 changes: 5 additions & 1 deletion app/php/Class/Validation.php
Expand Up @@ -9,6 +9,10 @@
class Validation
{
public function MaxSize($str, $size) {
return (mb_strlen($str, 'UTF-8') > $size) ? false : true;
return (mb_strlen($str, 'UTF-8') > $size);
}

public function Required($str){
return (empty($str));
}
}

0 comments on commit ed9aebc

Please sign in to comment.