Welcome Guest, Not a member yet? Register   Sign In
[Solved] Validate whether data entered in the input exists in the database - JQUERY
#1

(This post was last modified: 03-20-2020, 12:14 AM by jreklund.)

I have 3 inputs in the view. They 3 together identify a class from the school. (name, year and semester). So my idea was to validate these values before the submit button does all the data verification. 
I researched and found this example. 
Look the last example:
https://pt.stackoverflow.com/questions/1...-dados-php
But, it is not calling the controller / method.
The view´s inputs :
PHP Code:
<div class="form-group col-md-4">     
     
<label for="nturma">Turma</label>
     <input type="text" class="form-control" id="nturma" name="nturma" placeholder="Nº Turma">
</
div>
<
div class="form-group col-md-4">     
     
<label for="cletivo">Ano</label>
 
    <input type="text" class="form-control" id="cletivo" name="cletivo" placeholder="Ano">
</
div>   
<div class="form-group col-md-4">     
     
<label for="csemestre">Semestre</label>
     <input type="text" class="form-control" id="csemestre" name="csemestre" placeholder="Semestre">
 </div>   
I already checked, placing an Alert () inside the script to find out if the values of the inputs were correct.
This is a button in  a View.
PHP Code:
<div style="text-align:right">
    <button type="submit" class="btn btn-primary" id="btgravar" name="btgravar" >Gravar</button>
<
   ?= anchor('planodeaula/alertar/500''Voltar', array('class' => 'btn btn-danger')); ?>
 </div> 
Footer view file:
PHP Code:
<script>
          $(document).ready(function(){
            $('#btgravar').click(function(){$.post("<?php echo base_url();?>Planodeaula/verifica_turma",
            {
                nturma : $('#nturma').val(),
                cletivo : $('#cletivo').val(),
                csemestre : $('#csemestre').val()
                
            
},
            function (resp
            {
                var response jQuery.parseJSON(resp);
                alert("tudo funcionando 100%.");
                if(response === 'true')
                {
                    //$('#id_do_modal').modal('show');
                    alert("tudo funcionando 100%.");
                }else{
                    alert("NÃO funcionando !!!!!!!!!!!");
                }
            }    
            
});
    
    });
    </script

 Controller:

PHP Code:
public function verifica_turma() 
    {
    
alert(" FUNCIONA CABRUNCO !!!!!!!!!!!!!!!!!!!! ");
        $this->load->library('form_validation');
        $this->form_validation->set_rules('nturma','trim|required');
        $this->form_validation->set_rules('cletivo','trim|required');
        $this->form_validation->set_rules('csemestre','trim|required');
        if ($this->form_validation->run() === FALSE) {
            show_error('Estão faltando dados a preencher no formulario !');
        }
        else{
            show_error('Dados válidos!');
            echo json_encode($this->dia->check_turma());
            $resp=$this->dia->check_turma();
            if ($resp==true){
                alert(" turma existe ");
            }else{
                alert("não existe");
            }
            
        
}
    

Model :
PHP Code:
  function check_turma()
    {
        alert("Hello! I am an alert box!!");
        $nturma $this->db->escape_str($this->input->post('nturma'));
        $cletivo $this->db->escape_str($this->input->post('cletivo'));
        $csemestre $this->db->escape_str($this->input->post('csemestre'));
        $this->db->where('nturma',$nturma);
        $this->db->where('cletivo',$cletivo);    
        $this
->db->where('csemestre',$csemestre);
        $query $this->db->get(self::TABELA);
        if(!empty($query->result_array())){
            return TRUE;
        }
        return FALSE;
    
Do I have to change anything in routes.php ?
Routes.php
PHP Code:
$route['default_controller'] = 'Dashboard';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['aluno/(:num)'] = 'aluno/index/$1';
$route['turma/(:num)'] = 'turma/index/$1';
$route['curso/(:num)'] = 'curso/index/$1';
$route['disciplina/(:num)'] = 'disciplina/index/$1';
$route['professor/(:num)'] = 'professor/index/$1';
$route['diario/(:num)'] = 'diario/index/$1';
$route['dashboard/(:num)'] = 'dashboard/index/$1';
$route['senha/(:num)'] = 'senha/index/$1';
$route['administrativo/(:num)'] = 'administrativo/index/$1';
$route['notasturma/(:num)'] = 'notasturma/index/$1';
$route['Pdfexample/(:num)'] = 'pdfexample/index/$1';
$route['Planodeaula/(:num)'] = 'planodeaula/index/$1';
$route['Planodeaula/verifica'] = 'planodeaula/verifica_turma'
Reply


Messages In This Thread
[Solved] Validate whether data entered in the input exists in the database - JQUERY - by RRIOS - 03-17-2020, 12:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB