Skip to main content
replaced http://pt.stackoverflow.com/ with https://pt.stackoverflow.com/
Fonte Link

E está funcionando e carregando corretamente, conforme link este link.este link.

E está funcionando e carregando corretamente, conforme link este link.

E está funcionando e carregando corretamente, conforme link este link.

<?php

    $classActive = "";
    $divMenu = "";
    $divPanel = "";
    
    $this->db->order_by('id', 'asc');
    $this->db->where('usuario_id', $this->session->userdata('id'));
    $this->db->where('usuario_nome', $this->session->userdata('usuario_nome'));
    $nota = $this->db->get('nota')->result_array();
    $contador = 0;
    foreach ($nota as $row) {
        $classActive .= ($contador == 0) ? "active" : "inactive";
        //$divMenu = "<li class=\"" . $classActive . "\"><a href=\"#" . $row['id'] . "\" data-toggle=\"tab\"><i class=\"\"></i>" . $row['titulo'] . "</a></li>";
        $divPanel .= "
        <div class=\"tab-pane " . $classActive . "\" id=\"" . $row['id'] . "\">         
            <div id=\"sample\" class=\"ruledpaper\">
                <div class=\"form-group\" style=\"margin: 0px;\">
                    <div class=\"col-md-12\" style=\"padding:0px; background-color: #FFFCEE; font-size: 5px;\">
                        <input type=\"text\" class=\"form-control\" name=\"id\" value=\"" . $row['id'] . "\">
                        <input type=\"text\" class=\"form-control\" rows=\"14\" style=\"padding: 5px; border:0px; background-color: #fff6cc; font-size: 18px;\" name=\"titulo\" placeholder=\"Título\" value=\"" . $row['titulo'] . "\">
                    </div>
                </div>
                <hr style=\"margin: 0px;\" />
                <div class=\"form-group\">
                    <div class=\"col-md-12\" style=\"padding:0px;\">
                        <textarea maxlength=\"60\" class=\"ruledpaper form-control\" rows=\"\" cols=\"\" style=\"padding: 5px; border:0px; min-height: 350px;\" name=\"nota\" placeholder=\"Digite o texto...\">" . $row['nota'] . "</textarea>
                    </div>
                </div>
            </div>
        </div>";
        $contador++;
    }
?>
<form action="<?= base_url()?>admin/notas/salvar" id="" method="post" class="form-horizontal" >
<div class="row">
    <div class="col-sm-8">
        <div class="tab-content" style="width: 70%;">
            <?php echo $divPanel; ?>
            <div class="form-group">
                <div class="box-header" style="padding-left: 17px">             
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary btn-flat', 'content' => 'Salvar')); ?>
                    <?php echo form_button(array('type' => 'reset', 'class' => 'btn btn-warning btn-flat', 'content' => 'Limpar')); ?>
                    <?php echo anchor('admin/dashboard', 'Limpar', array('class' => 'btn btn-default btn-flat')); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <ul class="nav tabs-vertical">
        <?php foreach ($nota as $row){?>            
            <li class="">           
                <a href="#<?php echo $row['id'];?>" data-toggle="tab"> <i class=""></i> <?php echo $row['titulo'];?> </a>               
            </li>           
        <?php }?>
        </ul>       
    </div>
</div>
</form>

<?php

    $classActive = "";
    $divMenu = "";
    $divPanel = "";
    
    $this->db->order_by('id', 'asc');
    $this->db->where('usuario_id', $this->session->userdata('id'));
    $this->db->where('usuario_nome', $this->session->userdata('usuario_nome'));
    $nota = $this->db->get('nota')->result_array();
    $contador = 0;
    foreach ($nota as $row) {
        $classActive .= ($contador == 0) ? "active" : "inactive";
        //$divMenu = "<li class=\"" . $classActive . "\"><a href=\"#" . $row['id'] . "\" data-toggle=\"tab\"><i class=\"\"></i>" . $row['titulo'] . "</a></li>";
        $divPanel .= "
        <div class=\"tab-pane " . $classActive . "\" id=\"" . $row['id'] . "\">         
            <div id=\"sample\" class=\"ruledpaper\">
                <div class=\"form-group\" style=\"margin: 0px;\">
                    <div class=\"col-md-12\" style=\"padding:0px; background-color: #FFFCEE; font-size: 5px;\">
                        <input type=\"text\" class=\"form-control\" name=\"id\" value=\"" . $row['id'] . "\">
                        <input type=\"text\" class=\"form-control\" rows=\"14\" style=\"padding: 5px; border:0px; background-color: #fff6cc; font-size: 18px;\" name=\"titulo\" placeholder=\"Título\" value=\"" . $row['titulo'] . "\">
                    </div>
                </div>
                <hr style=\"margin: 0px;\" />
                <div class=\"form-group\">
                    <div class=\"col-md-12\" style=\"padding:0px;\">
                        <textarea maxlength=\"60\" class=\"ruledpaper form-control\" rows=\"\" cols=\"\" style=\"padding: 5px; border:0px; min-height: 350px;\" name=\"nota\" placeholder=\"Digite o texto...\">" . $row['nota'] . "</textarea>
                    </div>
                </div>
            </div>
        </div>";
        $contador++;
    }
?>
<form action="<?= base_url()?>admin/notas/salvar" id="" method="post" class="form-horizontal" >
<div class="row">
    <div class="col-sm-8">
        <div class="tab-content" style="width: 70%;">
            <?php echo $divPanel; ?>
            <div class="form-group">
                <div class="box-header" style="padding-left: 17px">             
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary btn-flat', 'content' => 'Salvar')); ?>
                    <?php echo form_button(array('type' => 'reset', 'class' => 'btn btn-warning btn-flat', 'content' => 'Limpar')); ?>
                    <?php echo anchor('admin/dashboard', 'Limpar', array('class' => 'btn btn-default btn-flat')); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <ul class="nav tabs-vertical">
        <?php foreach ($nota as $row){?>            
            <li class="">           
                <a href="#<?php echo $row['id'];?>" data-toggle="tab"> <i class=""></i> <?php echo $row['titulo'];?> </a>               
            </li>           
        <?php }?>
        </ul>       
    </div>
</div>
</form>

            $id = $this->input->post('id');
            
$data['titulo']                   =   $this->input->post('titulo');
$data['nota']                     =   $this->input->post('nota');
$data['usuario_nome']             =   $this->session->userdata('nome_usuario');
$data['usuario_id']               =   $this->session->userdata('id');
$data['dt_alteracao'] =  strtotime(date("d-m-Y H:i:s"));            
            
$this->db->where('id',$id);
            
if($this->db->update('nota', $data)){
echo $this->db->last_query();           
die();
                
redirect('admin/notas/index', $data);               
}
else
{
redirect('admin/notas/index', $data);
}

$id = $this->input->post('id');
                
$data['titulo']                   =   $this->input->post('titulo');
$data['nota']                     =   $this->input->post('nota');
$data['usuario_nome']             =   $this->session->userdata('nome_usuario');
$data['usuario_id']               =   $this->session->userdata('id');
$data['dt_alteracao'] =  strtotime(date("d-m-Y H:i:s"));            
                
$this->db->where('id',$id);
                
if($this->db->update('nota', $data)){
echo $this->db->last_query();           
die();
                    
redirect('admin/notas/index', $data);               
    }
else
    {
redirect('admin/notas/index', $data);
}

<?php

    $classActive = "";
    $divMenu = "";
    $divPanel = "";
    
    $this->db->order_by('id', 'asc');
    $this->db->where('usuario_id', $this->session->userdata('id'));
    $this->db->where('usuario_nome', $this->session->userdata('usuario_nome'));
    $nota = $this->db->get('nota')->result_array();
    $contador = 0;
    foreach ($nota as $row) {
        $classActive .= ($contador == 0) ? "active" : "inactive";
        //$divMenu = "<li class=\"" . $classActive . "\"><a href=\"#" . $row['id'] . "\" data-toggle=\"tab\"><i class=\"\"></i>" . $row['titulo'] . "</a></li>";
        $divPanel .= "
        <div class=\"tab-pane " . $classActive . "\" id=\"" . $row['id'] . "\">         
            <div id=\"sample\" class=\"ruledpaper\">
                <div class=\"form-group\" style=\"margin: 0px;\">
                    <div class=\"col-md-12\" style=\"padding:0px; background-color: #FFFCEE; font-size: 5px;\">
                        <input type=\"text\" class=\"form-control\" name=\"id\" value=\"" . $row['id'] . "\">
                        <input type=\"text\" class=\"form-control\" rows=\"14\" style=\"padding: 5px; border:0px; background-color: #fff6cc; font-size: 18px;\" name=\"titulo\" placeholder=\"Título\" value=\"" . $row['titulo'] . "\">
                    </div>
                </div>
                <hr style=\"margin: 0px;\" />
                <div class=\"form-group\">
                    <div class=\"col-md-12\" style=\"padding:0px;\">
                        <textarea maxlength=\"60\" class=\"ruledpaper form-control\" rows=\"\" cols=\"\" style=\"padding: 5px; border:0px; min-height: 350px;\" name=\"nota\" placeholder=\"Digite o texto...\">" . $row['nota'] . "</textarea>
                    </div>
                </div>
            </div>
        </div>";
        $contador++;
    }
?>
<form action="<?= base_url()?>admin/notas/salvar" id="" method="post" class="form-horizontal" >
<div class="row">
    <div class="col-sm-8">
        <div class="tab-content" style="width: 70%;">
            <?php echo $divPanel; ?>
            <div class="form-group">
                <div class="box-header" style="padding-left: 17px">             
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary btn-flat', 'content' => 'Salvar')); ?>
                    <?php echo form_button(array('type' => 'reset', 'class' => 'btn btn-warning btn-flat', 'content' => 'Limpar')); ?>
                    <?php echo anchor('admin/dashboard', 'Limpar', array('class' => 'btn btn-default btn-flat')); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <ul class="nav tabs-vertical">
        <?php foreach ($nota as $row){?>            
            <li class="">           
                <a href="#<?php echo $row['id'];?>" data-toggle="tab"> <i class=""></i> <?php echo $row['titulo'];?> </a>               
            </li>           
        <?php }?>
        </ul>       
    </div>
</div>
</form>

            $id = $this->input->post('id');
            
$data['titulo']                   =   $this->input->post('titulo');
$data['nota']                     =   $this->input->post('nota');
$data['usuario_nome']             =   $this->session->userdata('nome_usuario');
$data['usuario_id']               =   $this->session->userdata('id');
$data['dt_alteracao'] =  strtotime(date("d-m-Y H:i:s"));            
            
$this->db->where('id',$id);
            
if($this->db->update('nota', $data)){
echo $this->db->last_query();           
die();
                
redirect('admin/notas/index', $data);               
}
else
{
redirect('admin/notas/index', $data);
}

<?php

    $classActive = "";
    $divMenu = "";
    $divPanel = "";
    
    $this->db->order_by('id', 'asc');
    $this->db->where('usuario_id', $this->session->userdata('id'));
    $this->db->where('usuario_nome', $this->session->userdata('usuario_nome'));
    $nota = $this->db->get('nota')->result_array();
    $contador = 0;
    foreach ($nota as $row) {
        $classActive .= ($contador == 0) ? "active" : "inactive";
        //$divMenu = "<li class=\"" . $classActive . "\"><a href=\"#" . $row['id'] . "\" data-toggle=\"tab\"><i class=\"\"></i>" . $row['titulo'] . "</a></li>";
        $divPanel .= "
        <div class=\"tab-pane " . $classActive . "\" id=\"" . $row['id'] . "\">         
            <div id=\"sample\" class=\"ruledpaper\">
                <div class=\"form-group\" style=\"margin: 0px;\">
                    <div class=\"col-md-12\" style=\"padding:0px; background-color: #FFFCEE; font-size: 5px;\">
                        <input type=\"text\" class=\"form-control\" name=\"id\" value=\"" . $row['id'] . "\">
                        <input type=\"text\" class=\"form-control\" rows=\"14\" style=\"padding: 5px; border:0px; background-color: #fff6cc; font-size: 18px;\" name=\"titulo\" placeholder=\"Título\" value=\"" . $row['titulo'] . "\">
                    </div>
                </div>
                <hr style=\"margin: 0px;\" />
                <div class=\"form-group\">
                    <div class=\"col-md-12\" style=\"padding:0px;\">
                        <textarea maxlength=\"60\" class=\"ruledpaper form-control\" rows=\"\" cols=\"\" style=\"padding: 5px; border:0px; min-height: 350px;\" name=\"nota\" placeholder=\"Digite o texto...\">" . $row['nota'] . "</textarea>
                    </div>
                </div>
            </div>
        </div>";
        $contador++;
    }
?>
<form action="<?= base_url()?>admin/notas/salvar" id="" method="post" class="form-horizontal" >
<div class="row">
    <div class="col-sm-8">
        <div class="tab-content" style="width: 70%;">
            <?php echo $divPanel; ?>
            <div class="form-group">
                <div class="box-header" style="padding-left: 17px">             
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary btn-flat', 'content' => 'Salvar')); ?>
                    <?php echo form_button(array('type' => 'reset', 'class' => 'btn btn-warning btn-flat', 'content' => 'Limpar')); ?>
                    <?php echo anchor('admin/dashboard', 'Limpar', array('class' => 'btn btn-default btn-flat')); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <ul class="nav tabs-vertical">
        <?php foreach ($nota as $row){?>            
            <li class="">           
                <a href="#<?php echo $row['id'];?>" data-toggle="tab"> <i class=""></i> <?php echo $row['titulo'];?> </a>               
            </li>           
        <?php }?>
        </ul>       
    </div>
</div>
</form>
$id = $this->input->post('id');
                
$data['titulo']                   =   $this->input->post('titulo');
$data['nota']                     =   $this->input->post('nota');
$data['usuario_nome']             =   $this->session->userdata('nome_usuario');
$data['usuario_id']               =   $this->session->userdata('id');
$data['dt_alteracao'] =  strtotime(date("d-m-Y H:i:s"));            
                
$this->db->where('id',$id);
                
if($this->db->update('nota', $data)){
echo $this->db->last_query();           
die();
                    
redirect('admin/notas/index', $data);               
    }
else
    {
redirect('admin/notas/index', $data);
}
Fonte Link
Wagner Fillio
  • 1,3mil
  • 15
  • 40

Passando parâmetros corretos em submit de Formulário

Olá,

Estou tentando passar alguns parâmetros para o controller, mas não estou conseguindo.

O Código a seguir foi alterado para carregar o conteúdo do tab clicado e exibi-lo em um input e texarea.

E está funcionando e carregando corretamente, conforme link este link.

Agora eu preciso que, ao alterar qualquer coisa e feito o submit, a alteração seja gravada no banco.

Porem, quando envio o formulário, independente do ID que estou alterando, estou tendo o seguinte retorno:

UPDATE `nota` SET `titulo` = 'NOTA 5', `nota` = 'TEXTO NOTA 5', `usuario_nome` = 'Wagner Fillio', `usuario_id` = '1', `dt_alteracao` = 1481891781 WHERE `id` = '5'

Isto porque no memento tenho 5 notas gravadas no bd.

Veja abaixo o meu código view

<?php

    $classActive = "";
    $divMenu = "";
    $divPanel = "";
    
    $this->db->order_by('id', 'asc');
    $this->db->where('usuario_id', $this->session->userdata('id'));
    $this->db->where('usuario_nome', $this->session->userdata('usuario_nome'));
    $nota = $this->db->get('nota')->result_array();
    $contador = 0;
    foreach ($nota as $row) {
        $classActive .= ($contador == 0) ? "active" : "inactive";
        //$divMenu = "<li class=\"" . $classActive . "\"><a href=\"#" . $row['id'] . "\" data-toggle=\"tab\"><i class=\"\"></i>" . $row['titulo'] . "</a></li>";
        $divPanel .= "
        <div class=\"tab-pane " . $classActive . "\" id=\"" . $row['id'] . "\">         
            <div id=\"sample\" class=\"ruledpaper\">
                <div class=\"form-group\" style=\"margin: 0px;\">
                    <div class=\"col-md-12\" style=\"padding:0px; background-color: #FFFCEE; font-size: 5px;\">
                        <input type=\"text\" class=\"form-control\" name=\"id\" value=\"" . $row['id'] . "\">
                        <input type=\"text\" class=\"form-control\" rows=\"14\" style=\"padding: 5px; border:0px; background-color: #fff6cc; font-size: 18px;\" name=\"titulo\" placeholder=\"Título\" value=\"" . $row['titulo'] . "\">
                    </div>
                </div>
                <hr style=\"margin: 0px;\" />
                <div class=\"form-group\">
                    <div class=\"col-md-12\" style=\"padding:0px;\">
                        <textarea maxlength=\"60\" class=\"ruledpaper form-control\" rows=\"\" cols=\"\" style=\"padding: 5px; border:0px; min-height: 350px;\" name=\"nota\" placeholder=\"Digite o texto...\">" . $row['nota'] . "</textarea>
                    </div>
                </div>
            </div>
        </div>";
        $contador++;
    }
?>
<form action="<?= base_url()?>admin/notas/salvar" id="" method="post" class="form-horizontal" >
<div class="row">
    <div class="col-sm-8">
        <div class="tab-content" style="width: 70%;">
            <?php echo $divPanel; ?>
            <div class="form-group">
                <div class="box-header" style="padding-left: 17px">             
                    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary btn-flat', 'content' => 'Salvar')); ?>
                    <?php echo form_button(array('type' => 'reset', 'class' => 'btn btn-warning btn-flat', 'content' => 'Limpar')); ?>
                    <?php echo anchor('admin/dashboard', 'Limpar', array('class' => 'btn btn-default btn-flat')); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-4">
        <ul class="nav tabs-vertical">
        <?php foreach ($nota as $row){?>            
            <li class="">           
                <a href="#<?php echo $row['id'];?>" data-toggle="tab"> <i class=""></i> <?php echo $row['titulo'];?> </a>               
            </li>           
        <?php }?>
        </ul>       
    </div>
</div>
</form>

Vejam como está o controller

            $id = $this->input->post('id');
            
$data['titulo']                   =   $this->input->post('titulo');
$data['nota']                     =   $this->input->post('nota');
$data['usuario_nome']             =   $this->session->userdata('nome_usuario');
$data['usuario_id']               =   $this->session->userdata('id');
$data['dt_alteracao'] =  strtotime(date("d-m-Y H:i:s"));            
            
$this->db->where('id',$id);
            
if($this->db->update('nota', $data)){
echo $this->db->last_query();           
die();
                
redirect('admin/notas/index', $data);               
}
else
{
redirect('admin/notas/index', $data);
}