Last active
December 18, 2015 03:09
-
-
Save andersonfraga/5716387 to your computer and use it in GitHub Desktop.
Usando o Respect/Validation para validação.. Tem maneira mais simples de recuperar as falhas na validação?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Site\Controller; | |
use Respect\Validation\Validator as v; | |
class FormController extends BaseController | |
{ | |
public function faleAction() | |
{ | |
$postParams = $this->params()->fromPost(); | |
$strNotNull = v::string()->notEmpty(); | |
$errors = array(); | |
if (!$strNotNull->validate($postParams['con-name'])) { | |
$errors[] = 'o "Nome" não esteja vazio'; | |
} | |
if (!$strNotNull->email()->validate($postParams['con-mail'])) { | |
$errors[] = 'o "E-mail" não esteja vazio'; | |
} | |
if (!$strNotNull->validate($postParams['con-subject'])) { | |
$errors[] = 'o "Assunto" não esteja vazio'; | |
} | |
if (!$strNotNull->validate($postParams['con-msg'])) { | |
$errors[] = 'o "Mensagem" não esteja vazio'; | |
} | |
// .... | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment