Sinsil Mathew
Sinsil Mathew

Reputation: 498

How to navigate different tabs from controller in Codeigniter

I am new in CodeIgniter.I have a registration form view.Within this view there are several tabs like one for personal details,another for photo upload and another for job details.In first call i load the tab for personal details and there is a submit button for saving personal details.I want to navigate to photo upload tab after i submit the personal data.Is it possible to load photo uploading tab in the same view?

Upvotes: 1

Views: 9130

Answers (4)

Jithu
Jithu

Reputation: 68

Try this.. It Works for me.

View :

<?php $tab = (isset($tab)) ? $tab : 'tab1'; ?> 
<ul class="nav nav-tabs" id="myTabs">
    <li class="<?php echo ($tab == 'tab1') ? 'active' : ''; ?>" > 
        <a href="#tab_1_1" data-toggle="tab">Personal Info</a>
    </li>
    <li class="<?php echo ($tab == 'tab2') ? 'active' : ''; ?>" > 
        <a href="#tab_1_2" data-toggle="tab">Family Info</a>
    </li>
    <li class="<?php echo ($tab == 'tab3') ? 'active' : ''; ?>" > 
        <a href="#tab_1_3" data-toggle="tab">Upload Photo</a>
    </li>
</ul>

and for each tab-pane set class as :

<div class="tab-pane <?php echo ($tab == 'tab1') ? 'active' : ''; ?>" id="tab_1_1">

Update your controller as:

$data['tab'] = 'tab3';

    $this->load->view('commons/header');
    $this->load->view('addmember',$data);
    $this->load->view('commons/footer');

Tis code will show 1st tab (Personal info) as the default tab and after submission of 1st tab, it navigate to the 3rd tab (Upload Photo). You can change it to the 2nd tab if needed.

Hope this will help you.

Upvotes: 1

Shaiful Islam
Shaiful Islam

Reputation: 7134

I don't know how your view looks like.Here is a way that may help you.
First write a function at your controller like this

function myFunction($tab=1)//may be index
{
   $data['tab']=$tab;
   //do other stuff
   if($tab==2)
   {
      //save personal details
       $data['id']=the_id_you_saved;
   }
   //suppose your last tab is 3
   if($tab==3)
   {
       //do your stuff or redirect
   }
   $this->load->view('your_tab_view', $data);

}

Now your view file will look like this.

//load your other htmls
<?php
    if($tab==1)
    {
     ?>
      <form action="controler_name/myFunction/2" method="post">
         //your personal information form
      </form>
     <?php
    }
    else if($tab==2)
    {
    ?>
     <form action="controler_name/myFunction/3" method="post">
       <input type="hidden" name="id" value="<?php echo $id ?>">
         //your file upload form
      </form>
    <?php        
    }
?>

Hope you will get the idea how to do that. Thanks

Upvotes: 1

suman halder
suman halder

Reputation: 1

$user['details'] = array('name=>test','email=>[email protected]'); $this->load->view('header'); $this->load->view('addphoto',$user); $this->load->view('footer');

I have give you a sample structure for controller page. From where you can call the add photo and send user details.

Upvotes: 0

John
John

Reputation: 889

I have a suggestion, though there may be other ways of doing it.

In the view you create three tabs and load the view in each tabs through ajax. This can be done like when you click submit of the first tab if successful it returns the view for the next tab and on ajax success you display the next tab making the previous tab as display:none;

similarly other tabs. Using templates this can be achieved easily.

Upvotes: 0

Related Questions