how to pass variable to a second tab

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    how to pass variable to a second tab

    i have a page which is home.php on that page i have a CSS tab which is tab1 and tab2 on that page in both tabs i have a link called next that pass variable to the next page (<a href='home.php? page=$lastpage' >NEXT</a>).if i click on next in the tab1 on home page(home.php) it will pass the variable and bring me to the home page and tab1 if i click on the next in tab2 it will also bring me to home page and take me to tab1 back.i want it to bring meto the home page and tab2 how can i do that.

    Code:
    <html>
    <head>
    <title></title>
    <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    
    <?php
    if (isset($_GET['page'])) {
    $pages = ($_GET['page']);
    } else {
    echo "page one";
    }
    ?>
    
    <ul class="TabbedPanelsTabGroup">
    <li class="TabbedPanelsTab" tabindex="0">Tab1</li>
    <li class="TabbedPanelsTab" tabindex="0">Tab2</li>
    </ul>
    
    <div class="TabbedPanelsContent">
    <div class="tabb">
    <?php
    echo "<a href='home.php?page=$lastpage'>NEXT</a>";
    ?>
    </div></div>
    
    <div class="TabbedPanelsContent">
    <div class="tab">
    <?php
    echo "<a href='home.php?page=$lastpage'>NEXT</a>";
    ?>
    </div></div>
    
    </head>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    er, could you rephrase your question please, I didn’t get what you want.

    Comment

    • simon2x1
      New Member
      • Dec 2008
      • 123

      #3
      i want tab2 to display if i click on the link Next in tab2 it should not take me back to tab1

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        So you need to track which tab you're on. Either making a $_SESSION variable to include current_tab or something, or using $_POST / $_GET...

        I would go with $_SESSION so you don't have to submit to move pages ($_POST) and you don'r have to change URLs ($_GET).

        Comment

        • simon2x1
          New Member
          • Dec 2008
          • 123

          #5
          Originally posted by TheServant
          So you need to track which tab you're on. Either making a $_SESSION variable to include current_tab or something, or using $_POST / $_GET...

          I would go with $_SESSION so you don't have to submit to move pages ($_POST) and you don'r have to change URLs ($_GET).
          how can i track the tab and also make a $_SESSION variable to include current_tab

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            Originally posted by simon2x1
            how can i track the tab and also make a $_SESSION variable to include current_tab
            You should read up on $_SESSION's, but they are very similar to other variables. You could also use $_COOKIE's which will be able to remember which tab they're on even if they close the browser and come back in a week.
            Code:
            // To set a session variable:
            $_SESSION['current_tab'] = "About Tab";
            // To recall a session variable:
            if ($_SESSION['current_tab'] == $current_tab_name) {
            echo "selected";
            }
            That conditional statement can obviously be anything and you would use it to show a css property, or call a javascript function or however you're tracking which tab to display.

            Also when you're using sessions you need to tell PHP you're going to be using sessions on every page. You need to put this line at the top of every page that will use the $_SESSION super variable:
            Code:
            session_start();

            Comment

            • simon2x1
              New Member
              • Dec 2008
              • 123

              #7
              how to pass variable to a second tab

              i still did not get it well help me take a look at my code below and tell me what the problem his
              Code:
              <?php
              
              session_start();
              $_SESSION['TabbedPanelsTab'] = "About Tab";
              if ($_SESSION['TabbedPanelsTab'] == $current_tab_name) { 
              echo "selected"; 
              }   
              ?>
              
              <html> 
              <head> 
              <title></title> 
              <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css" /> 
                
              <?php 
              if (isset($_GET['page'])) { 
              $pages = ($_GET['page']); 
              } else { 
              echo "page one"; 
              } 
              ?> 
                
              <ul class="TabbedPanelsTabGroup"> 
              <li class="TabbedPanelsTab" tabindex="0">Tab1</li> 
              <li class="TabbedPanelsTab" tabindex="0">Tab2</li> 
              </ul> 
                
              <div class="TabbedPanelsContent"> 
              <div class="tabb"> 
              <?php 
              echo "<a href='home.php?page=$lastpage'>NEXT</a>"; 
              ?> 
              </div></div> 
                
              <div class="TabbedPanelsContent"> 
              <div class="tab"> 
              <?php 
              echo "<a href='home.php?page=$lastpage'>NEXT</a>"; 
              ?> 
              </div></div> 
                
              </head> 
              </html>

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                Where do you get your $current_tab_na me? There is no definition there?

                To get into more specifics, the question is how do you intend on changing tabs? Will your tabs be different pages, or will all content be loaded and then tabs only show selected content. The second option is more user friendly, but will require javascript, and will not be great for SEO and page tracking.

                If you are reloading every time a tab is changed, maybe session variables will not be ideal and a nicer $_GET variable will be easier, as you probably don't want to start doing AJAX functions between changing pages... Maybe you do? If it's just changing tabs, a $_GET should be fine, and with some .htaccess tricks, you can make pretty URL's.

                Comment

                • simon2x1
                  New Member
                  • Dec 2008
                  • 123

                  #9
                  the tabs are on the same page not different pages am talking about the content of the tabs i want the content of tab2 to display when ever i click submit button in the content of tab2 not to take me back to tab1.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    the submit button does not take you back to tab1. it just loads the page with the default setting, which is probably tab1.

                    Comment

                    • kovik
                      Recognized Expert Top Contributor
                      • Jun 2007
                      • 1044

                      #11
                      If you have these tabs inside of one page, I'd recommend doing one of two things:
                      1. Using the query string and $_GET, or
                      2. Using JavaScript to display the tabs.


                      Session data is for preserving data across page requests. What you are making IS a page request, and does not represent data that should persist across requests. What you want to do is, basically, just make your tabs into links. Plain and simple.


                      Code:
                      <?php
                      $active_tab = isset($_GET['tab']) ? (int)$_GET['tab'] : 0;
                      $tabs = array(
                        1 => 'Tab 1',
                        2 => 'Tab 2',
                      );
                      ?>
                      <ul id="tabs>
                        <?php foreach ($tabs as $tab_id => $tab_name): ?>
                        <li<?php if ($active_tab == $tab_id) echo ' class="active"'; ?>>
                          <a href="?tab=<?php echo $tab_id; ?>"><?php echo $tab_name; ?></a>
                        </li>
                        <?php endforeach; ?>
                      </ul>
                      <div id="tab-content">
                      <?php if ($active_tab == 1): ?>
                      This content is in tab #1.
                      <?php elseif ($active_tab == 2): ?>
                      This content is in tab #2.
                      <?php else: ?>
                      The tab that you have selected is invalid. Sneaky, sneaky.
                      <?php endif; ?>
                      </div>
                      Then, you'd style the tabs with CSS and add whatever other logic you want.

                      Comment

                      • simon2x1
                        New Member
                        • Dec 2008
                        • 123

                        #12
                        i want to thank you for your reply i will appreciate it if i will be able to use JavaScript to solve this problem using this php code make me more confess please i need the java script version that can solve this problem

                        Comment

                        • kovik
                          Recognized Expert Top Contributor
                          • Jun 2007
                          • 1044

                          #13
                          I'm sorry, but if you can't do this yourself, chances are trying to explain how to use my code would go over your head anyway. Good luck, though.

                          Comment

                          Working...