Codeigniter with Modal Screen and Registration Response

Asked

Viewed 1,299 times

1

I am making a registration of call requests through a modal but I can not handle the registration answer: "Register with Success"

inserir a descrição da imagem aqui

Controlling class

 <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

    function __construct(){
        parent::__construct();
    }

    function index() {
            $data['titulo']= "Administração";
            if($this->session->userdata('logged_in'))
            {
              $session_data = $this->session->userdata('logged_in');
              $data['nomeUsuario'] = $session_data['nomeUsuario'];
              $data['nomeEmpresa'] = $session_data['nomeEmpresa'];
              $data['tipoUsuario'] = $session_data['tipoUsuario'];

              if($data['tipoUsuario']=='1'){ //administrador

                $minha_query = "select DISTINCT * from solicitantes";
                $query = $this->db->query($minha_query);
        $data['solicitantes']= $query->result();



                $this->load->view('adm/html_header',$data);
                $this->load->view('adm/html_cabecalho',$data);    
                $this->load->view('adm/conteudo',$data);
                $this->load->view('adm/html_footer');

             }elseif ($data['tipoUsuario']=='2') { //tecnico
                $this->load->view('tec/html_header',$data);    
                $this->load->view('tec/html_cabecalho',$data);    
                $this->load->view('tec/conteudo',$data);
                $this->load->view('tec/html_footer');

             }elseif ($data['tipoUsuario']=='3') { 
                $this->load->view('cliente/html_header',$data);    
                $this->load->view('cliente/html_cabecalho',$data);    
                $this->load->view('cliente/conteudo',$data);
                $this->load->view('cliente/html_footer');

             }elseif ($data['tipoUsuario']=='4') {  //cliente
                $this->load->view('atende/html_header',$data);    
                $this->load->view('atende/html_cabecalho',$data);    
                $this->load->view('atende/conteudo',$data);
                $this->load->view('atende/html_footer'); 
             }

            }
            else
            {
              //If no session, redirect to login page
              redirect('login', 'refresh');
            }
    }   

        public function solicitacaoRapida(){
            $this->load->model('sgc');

            $this->db->insert('solicitacoes',$this);

            $banco = array(
            'solicitante'   =>  $this->input->post('empresaSolicitante'),
            'local'     =>  $this->input->post('localEmpresa'),
            'departamento'  =>  $this->input->post('nomeDepartamento'),
            'assunto'   =>  $this->input->post('tipoSolicitacao')
        );
        $this->insert($banco);
        redirect(base_url().'home','refresh');


        }

    public function logout(){
            $this->session->unset_userdata('logged_in');
            session_destroy();
            redirect('Login', 'refresh');           
    }

}
?>

View

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Bem Vindo <?php echo $nomeUsuario; ?> </title>
    <meta charset="utf-8">
    <link  href="<?= base_url();?>assets/css/bootstrap.css" rel="stylesheet">
    <script src="<?= base_url();?>assets/js/jquery-1.12.3.min.js"></script>
    <script src="<?= base_url();?>assets/js/bootstrap.min.js"></script>
</head>
<body>

    <!-- Parte de cima -->
    <div>
        <p>
            <h5>Bem Vindo,  <?php echo $nomeUsuario; ?>  | <?php echo $nomeEmpresa; ?>  </h5>
        </p>

    </div>

    <div class="text-right">
        <p>
            <h5> <a href="" data-toggle="modal" data-target="#AssistenteConf"> Assistente de Configuração</a> | <a href="" data-toggle="modal" data-target="#SolicitacaoRapida">Solicitação Rápida</a> | <a data-toggle="modal" data-target="#trocarSenha">Troca Minha Senha</a> | <a href="home/logout">Logout </a> |</h5>
        </p>

    </div>


     <!-- Modal AssistenteConfiguracao-->
        <div class="modal fade" id="AssistenteConf" name="AssistenteConf" role="dialog">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="btrocarSenhautton" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Assistente de Configuração</h4>
                    </div>
                    <div class="modal-body">
                        <form action='<?= base_url();?>index.php/recuperarSenha' method="" id="formRecuperarSenha" name="formRecuperarSenha">

                        </form> 
                    </div>

                    <div class="modal-footer">
                        <button type="submit" class="btn btn-success">Recuperar</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                    </div>

                </div>
            </div>
        </div>


    <!-- Modal Solicitacao Rapida-->
        <div class="modal fade" id="SolicitacaoRapida" name="SolicitacaoRapida" role="dialog">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">

                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Solicitação Rápida </h4>
                    </div>

                    <div class="modal-body">

                        <form action='<?= base_url();?>index.php/home/solicitacaoRapida' method="post" id="formRecuperarSenha" name="formRecuperarSenha">
                            <p>
                                <b>Solicitante:</b><span style="color:red">*</span>
                                <select name="empresaSolicitante">
                                    <option value=""> Selecione </option>
                                   <?php
                                     foreach ($solicitantes as $value) { 
                                        echo  "<option value=".$value->idsolicitantes.">".$value->nomeSolicitante."</option>";

                                     }
                                  ?>
                                </select>    
                            </p>

                            <p>
                                <b>Local:</b><span style="color:red">*</span>

                                <select name="localEmpresa">
                                    <option value=""> Selecione </option>
                                    <?php  
                                        foreach ($solicitantes as $value) { 
                                        echo  "<option value=".$value->idsolicitantes.">".$value->local."</option>";  
                                     }
                                  ?>
                                </select>    
                            </p>

                            <p><b>Departamento:</b><span style="color:red">*</span>

                                <select name="nomeDepartamento">
                                    <option value=""> Selecione </option>
                                     <?php  
                                        foreach ($solicitantes as $value) { 
                                          echo  "<option value=".$value->idsolicitantes.">".$value->departamento."</option>";  
                                     }
                                  ?>
                                </select>    
                            </p>   

                            <p>
                               <b>Tipo:</b><span style="color:red">*</span>

                                <select name="tipoSolicitacao">
                                    <option value="1">Iniciante</option>
                                    <option value="2">Solicitação de Informação</option>
                                    <option value="3">Solicitação de Serviço</option>
                                </select> 
                            </p>

                            <p>
                                <b>Assunto:</b><span style="color:red">*</span>
                                <input name="assuntoSolicitacao" id="assuntoSolicitacao" type="text"> 
                            </p>

                            <!-- Input para anexar imagem do erro da tela
                            <p>
                                <b>Anexo:</b><span style="color:red">*</span>
                                <input name="anexoSolicitacao" id="anexoSolicitacao" type="text"> 
                            </p>
                            -->

                            <p>
                                <b>Descrição:</b><span style="color:red">*</span></p>
                                <textarea name="descricaoSolicitacao" id="descricaoSolicitacao" rows="4" cols="30">
                                </textarea>
                            </p>

                        </table>

                        </form> 
                    </div>

                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success" value="Salvar"></input>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                    </div>

                </div>
            </div>
        </div>


     <!-- Modal Trocar Senha-->
        <div class="modal fade" id="trocarSenha" name="trocarSenha" role="dialog">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Trocar Senha</h4>
                    </div>
                    <div class="modal-body">
                        <form action='<?= base_url();?>index.php/recuperarSenha' method="" id="formRecuperarSenha" name="formRecuperarSenha">
                            <p><b>Nova Senha</b><span style="color:red">*</span></p>
                            <p><input type="password" name="novaSenha" id="novaSenha"></p>

                            <p><b>Confirmar Senha:</b><span style="color:red">*</span><p/>
                            <p><input type="password" name="confirmarSenha" id="confirmarSenha" title="Inserir login do usuario"></p>


                        </form> 
                    </div>

                    <div class="modal-footer">
                        <button type="submit" class="btn btn-success">Salvar</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
                    </div>

                </div>
            </div>
        </div>

2 answers

2

It would also be more interesting to use models to bring data from the database rather than directly from the controller.

2


Before the redirect you can add some data in the flashdata session to have access only in the next redirect.

Do:

$this->session->set_flashdata('mensagem', 'Cadastrado com sucesso!');

In the view you will have access to the variable this way:

$this->session->flashdata('mensagem');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.