• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forms displaying multiple times using for each loop

#1
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

#2
Wrong forum, no exact problem a lot of code and some request ..

Usually for such tasks people pay something to the developer who will fix it..
Best VPS Hosting : Digital Ocean
Reply

#3
@sheenam,

I don't see a model where you only get the data for a specific record (based on taxid). When you click edit what controller is called?
Reply

#4
This needs to be moved to the correct forum.

This is for CI 4 only.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(11-15-2016, 06:26 AM)php_rocs Wrote: @sheenam,

I don't see a model where you only get the data for a specific record (based on taxid).  When you click edit what  controller is called?

@php_rocks thanks for replying back as everyone is giving negative reply here. thanku so much.
this function for model
function gettaxid()
{
 
   $this->db->select('*');
 
   $this->db->from('tax_master');
 
   $query $this->db->get();    
    return $query
->result();
}

this for controller:
  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);  
 
}
Reply

#6
(11-15-2016, 06:59 AM)InsiteFX Wrote: This needs to be moved to the correct forum.

This is for CI 4 only.

hi which is the correct forum can u plz suggest.?
Reply

#7
(11-15-2016, 09:55 PM)sheenam Wrote:
(11-15-2016, 06:26 AM)php_rocs Wrote: @sheenam,

I don't see a model where you only get the data for a specific record (based on taxid).  When you click edit what  controller is called?

@php_rocks thanks for replying back as everyone is giving negative reply here. thanku so much.
this function for model
function gettaxid()
{
 
   $this->db->select('*');
 
   $this->db->from('tax_master');
 
   $query $this->db->get();    
    return $query
->result();
}

this for controller:
  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);  
 
}


and i need to call the update controller which is giving me this problem. how can i acheive the solution.
Reply

#8
(11-15-2016, 06:11 AM)sv3tli0 Wrote: Wrong forum, no exact problem a lot of code and some request ..

Usually for such tasks people pay something to the developer who will fix it..

dear @sv3tlio
can you plz help me out finding the error
Reply

#9
(11-15-2016, 09:59 PM)sheenam Wrote:
(11-15-2016, 06:59 AM)InsiteFX Wrote: This needs to be moved to the correct forum.

This is for CI 4 only.

hi which is the correct forum can u plz suggest.?

The Forum is: Using CodeIgniter - General Help
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#10
(11-16-2016, 03:24 AM)InsiteFX Wrote:
(11-15-2016, 09:59 PM)sheenam Wrote:
(11-15-2016, 06:59 AM)InsiteFX Wrote: This needs to be moved to the correct forum.

This is for CI 4 only.

hi which is the correct forum can u plz suggest.?

The Forum is: Using CodeIgniter - General Help
Is this what you are talking about??
attached the screenshot kindly check it


Attached Files Thumbnail(s)
   
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.