Welcome Guest, Not a member yet? Register   Sign In
Forms displaying multiple times using for each loop
#1

(This post was last modified: 11-15-2016, 04:24 AM by sheenam.)

hi all,

i m trying to update the values in a popup form and when i press edit i get the form with all values their in database.
here is my code:

Controller:

PHP Code:
<?php

if (!defined('BASEPATH'))
 
   exit('No direct script access allowed');

class 
Tax extends CI_Controller {

 
 
    public 
function __construct() {
 
       parent::__construct();
 
       $this->load->library('form_validation');
 
       $this->load->model("settings/insert_tax");
 
        if (!$this->session->userdata('is_admin_login')) {
 
           redirect('home');
 
       }
 
   }

 
   public function index() 
    {

 
   $query $this->db->get("tax_master"); 
 
   $data['record'] = $query->result(); 
$data['records'] = $query->result(); 
    
$data['page']='taxes';

    
$this->load->view("settings/vwTaxes" $data);
    
    }
    public function 
addtax()
    {
     
$this->load->model('settings/insert_tax');
     
     
$this->load->library('form_validation');


//Validating Name Field
$this->form_validation->set_rules('tax_name''Taxname');

//Validating Email Field
$this->form_validation->set_rules('tax_percent''Taxpercent''required');



if (
$this->form_validation->run() == FALSE)
    {
$this->load->view('settings/vwTaxes');

 
 $err['error'] = '<strong>fill in all the details</strong>'   
 redirect
('settings/tax');  

else {
    
//Setting values for tabel columns
$data = array(
'tax_name' => $this->input->post('tax_name'),
'tax_percent' => $this->input->post('tax_percent'),

);
 unset(
$_POST);
 
 
   
$this
->insert_tax->inserttax($data);

 
          $this->load->view("settings/vwTaxes",$data);              
        redirect
('settings/tax');
}
    }
 
    public function taxlist() 
 
 {

 
        $this->load->model('insert_tax');  
     
         $data
['records']=$this->insert_tax->gettaxid();  
         
//return the data in view  
 
        $this->load->view('settings/vwTaxes'$data);  
 
}
 
 public function 
updatetaxes()
 
 {
$id=$this->input->get('t_id');
 
   
    $this
->load->model('insert_tax');
 
    $data = array(
 
          'tax_name' => $this->input->post('tax_name'),
 
          'tax_percent'=> $this->input->post('tax_percent'),
 
          
            
);
$data["records"]=$this->insert_tax->updatetax($id); 

 
$this->form_validation->set_rules('tax_name','Name','trim|required');
$this->form_validation->set_rules('tax_percent','Name','trim|required');
 
 
        if 
($this->form_validation->run() == FALSE) {
 
          $this->load->view('settings/vwTaxes');
 
       }
 
         
      $this
->load->view("settings/vwTaxes",$data); 
 
   
  redirect
('settings/tax');
 
   }
 
 
  public 
function deletetaxes()
 
 {
 
     
      $id
=$this->input->get('tid');
 
   
    $this
->load->model('insert_tax');
 
    
      
      $delete 
= array(
 
          't_id' => $this->input->post('t_id'),
 
          
            
);
$delete["record"]=$this->insert_tax->deletetax($id); 
 
 
                   
      $this
->load->view("settings/vwTaxes",$delete); 
 
   
  redirect
('settings/tax');
 
 }


}
 
  
Model:
PHP Code:
<?php
class Insert_tax extends CI_Model{
function 
__construct()
 {
parent::__construct();
}


function 
inserttax($data)

{
$query$this->db->insert('tax_master'$data);

return 
$query;
}
function 
gettaxid()
{
 
   $this->db->select('*');
 
   $this->db->from('tax_master');
 
   $query $this->db->get();    
    return $query
->result();
}
function 
updatetax($id)
{

 
$data = array(
 
         'tax_name'  =>  $_POST['tax_name'] ,
 
         'tax_percent'  =>  $_POST['tax_percent'] ,
 
  
);

$this->db->where('t_id'$id);

$this->db->update('tax_master'$data);

 
   $query $this->db->get('tax_master');    
  return $query
->result();
    
}
function 
deletetax($id)
{


$this->db->where('t_id'$id);

$this->db->delete('tax_master');

 
   $query $this->db->get('tax_master');    
  return $query
->result();
    
}

View:
Quote:<html>

<body>
<div class="content-wrapper">
     <section class="content">    
     <div class="row">
   <div class="box box-primary">
  <div class="box-header">
 <div class="col-lg-6 col-offset-6 col-md-offset-5 col-xs-6">
        <div class="btn-group">

          <button class="btn btn-info btn-flat" data-toggle="modal" data-target="#loginModal"><i class="fa fa-plus"></i>Add Taxes</button>
</p>

<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="Login" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
   <h3 class="modal-title" id="myModalLabel">Add Lead</h3>
            </div>
       <div class="modal-body">
                <!-- The form is placed inside the body of modal -->
      <?php echo form_open('settings/tax/addtax',['class'=>'form-horizontal panel' , 'method'=> 'POST']); ?>
              
                    <div class="form-group">
                        <label class="col-xs-3 control-label"><h4>Tax Name</h4></label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" placeholder="Tax Name" name="tax_name" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-3 control-label"><h4>Tax Percentage</h4></label>
                        <div class="col-xs-8">
                        <input type="text" class="form-control" placeholder="Tax Percentage" name="tax_percent" />
                        </div>
                    </div>
  
           
                    <div class="form-group">
                        <div class="col-xs-8 col-xs-offset-5">
            <?php 

echo form_reset(['name'=>'cancel', 'data-dismiss'=>'modal'  , 'value'=>'Reset' , 'class'=>'btn btn-default']); 

?>
  <?php 
 
 echo form_submit(['name'=>'submit' , 'value'=>'Submit' , 'class'=>'btn btn-primary']);

 ?>
       
</div>             
 </div>
</form>
</div>   
         
</div>
 </div>
 </div>
 </div>
 </div>  
 </div> 
</div>
</div>
    <section class="content"> 
     <div class="row">
     <div class="col-lg-12 col-xs-12">
<table  class="table table-bordered table-striped">
   
     <tr>
      <thead>
      <th>Tax Name</th>
       <th>Tax Percentage(%)</th>
         <th colspan="2">Action</th>
     </thead>
     </tr>
             <?php  
    
   foreach ($record as $row)  
         {  
     
    ?>
   <tbody>
    <tr>
      <?php  $row->t_id;?>
   <td><?php echo $row->tax_name;?></td>  
    <td><?php echo $row->tax_percent;?></td> 

  <td><a data-toggle="modal"   data-target="#editModal">Edit</i></a></td>
 <td class="text-center"><a href="<?php echo base_url("settings/tax/deletetaxes?tid=" .$row->t_id);?>"
 onClick="return doconfirm();">Delete</a></td>
   </tr>
    </tbody>
        <?php
     }
    ?>
   
  </table>

// **this is the update form**//

   <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="Login" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
               <span aria-hidden="true">&times;</span>
                </button>
   <h3 class="modal-title" id="myModalLabel">Update Taxes</h3>
            </div>
       <div class="modal-body">
       
        <?php
foreach($records as $row)
{
  ?>

  <?php echo form_open("settings/tax/updatetaxes?t_id=".$row->t_id,['class'=>'form-horizontal panel' , 'method'=> 'POST']); ?>
     
   <div class="form-group">

  <label class="col-xs-3 control-label"><h4>Tax Name</h4></label>
   <div class="col-xs-8">
     <input type="hidden" class="form-control" name="t_id"  />
      <input type="text" class="form-control" placeholder="Tax Name" name="tax_name" value="<?php echo $row->tax_name ;?>" />
            </div>
          </div>
    <div class="form-group">
            <label class="col-xs-3 control-label"><h4>Tax Percentage</h4></label>
                <div class="col-xs-8">
             <input type="text" class="form-control" placeholder="Tax Percentage" name="tax_percent" value="<?php echo $row->tax_percent ;?>" />
                 </div>
             </div>
<div class="form-group">
        <div class="col-xs-8 col-xs-offset-5">
            <?php 

echo form_reset(['name'=>'cancel', 'data-dismiss'=>'modal'  , 'value'=>'Reset' , 'class'=>'btn btn-default']); 

?>
 
 
 <?php 
 
 echo form_submit(['name'=>'submit' , 'value'=>'Submit' , 'class'=>'btn btn-primary']);

 ?>
   </div>
                   
 </form>
<?php
}
?>
 </div>   
  </div>   </div>  
       <script type="text/javascript">

function doconfirm()
{
    job=confirm("Are you sure to delete permanently?");
    if(job!=true)
    {
        return false;
    }
}

    </script> 
   
</div>

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

</div></div>

</div>
          <div class="box box-primary">
            <div class="box-header"> 
             <div class="box-body">
          </div>   
            </div>
          </div>
        </section>
    </section>
</body>

</html>
and i am attaching the screenshots of the form
Plz help me ..
thanks in advance!!
Regards,
Sheenam

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
Forms displaying multiple times using for each loop - by sheenam - 11-15-2016, 04:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB