Guest User

Untitled

a guest
Jun 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /***** Validação *****/
  3.  
  4. function validateBanda($ajax = true) {
  5. // Mensagens
  6.  
  7. $msgVazio = 'Ops, o campo de %s está vazio!';
  8. $msgSelect = 'Você precisa selecionar uma opção no campo %s!';
  9. $msgLogin = 'O login escolhido já existe!';
  10. $msgSenha = 'Sua senha não pode ser igual ao seu login.';
  11. $msgResenha = 'A confirmação da sua senha não confere!';
  12. $msgEmail = 'E-mail inválido.';
  13. $msgFoto = 'Ops, houve um erro ao enviar sua foto!';
  14. $msgTermos = 'Você precisa aceitar os termos antes de continuar.';
  15. $msgBoxes = 'Selecione ao menos uma opção para os %s.';
  16.  
  17. $this->form_validation->set_message('required', $msgVazio);
  18. $this->form_validation->set_message('is_natural_no_zero', $msgSelect);
  19. $this->form_validation->set_message('matches', $msgResenha);
  20. $this->form_validation->set_message('_userCheck', $msgLogin);
  21. $this->form_validation->set_message('_boxesCheck', $msgBoxes);
  22. $this->form_validation->set_message('_termosCheck', $msgTermos);
  23. $this->form_validation->set_message('_nomatches', $msgSenha);
  24.  
  25. // Regras
  26. $fields = array('geLogin', 'geSenha', 'geResenha', 'geEmail', 'inNome',
  27. 'inEstado', 'inCidade', 'inBairro', 'muRelease',
  28. 'muGenero1', 'muGenero1', 'muGenero1', 'muObjetivos',
  29. 'muTempo', 'iaIntegrantes', 'mpMusicos', 'ctContato', 'frTermos');
  30. $this->form_validation->set_rules('geLogin', 'Login', 'trim|required|min_length[5]|max_length[20]|callback__userCheck');
  31. $this->form_validation->set_rules('geSenha', 'Senha', 'required|matches[geResenha]|callback__nomatches[geLogin]');
  32. $this->form_validation->set_rules('geResenha', 'Confirmação', 'required');
  33. $this->form_validation->set_rules('geEmail', 'E-mail', 'required|valid_email');
  34. $this->form_validation->set_rules('inNome', 'Nome', 'required');
  35. $this->form_validation->set_rules('inEstado', 'Estado', 'is_natural_no_zero');
  36. $this->form_validation->set_rules('inCidade', 'Cidade', 'is_natural_no_zero');
  37. $this->form_validation->set_rules('inBairro', 'Bairro', 'trim|required');
  38. $this->form_validation->set_rules('muRelease', 'Release', 'required');
  39. $this->form_validation->set_rules('muGenero1', 'Gênero 1', 'is_natural_no_zero');
  40. $this->form_validation->set_rules('muObjetivos', 'Objetivos', 'is_natural_no_zero');
  41. $this->form_validation->set_rules('muTempo', 'Experiência', 'required|is_natural');
  42. $this->form_validation->set_rules('iaIntegrantes', 'Integrantes', 'callback__boxesCheck');
  43. $this->form_validation->set_rules('mpMusicos', 'Músicos', 'callback__boxesCheck');
  44. $this->form_validation->set_rules('ctContato', 'Contatos', 'required');
  45. $this->form_validation->set_rules('frTermos', 'Termos', 'callback__termosCheck');
  46.  
  47. if ($this->form_validation->run()) {
  48.  
  49. }
  50. else {
  51. // echo $this->form_validation->error_string();
  52. foreach ($fields as $field) {
  53. $error[$field] = form_error($field);
  54. }
  55. return $error;
  56. }
  57.  
  58. }
  59.  
  60. /***** Funções validação *****/
  61.  
  62. function _userCheck($login) {
  63. return !$this->UsuariosModel->userExists($login);
  64. }
  65.  
  66. function _boxesCheck($campo) {
  67. return (is_array($campo) && count($campo) > 0);
  68. }
  69.  
  70. function _termosCheck($termos) {
  71. return $termos == 'on';
  72. }
  73.  
  74. function _nomatches($a, $b) {
  75. return !$this->form_validation->matches($a, $b);
  76. }
  77.  
  78.  
  79. ?>
Add Comment
Please, Sign In to add comment