Foros del Web » Programando para Internet » PHP »

No consigo cambiar de tab

Estas en el tema de No consigo cambiar de tab en el foro de PHP en Foros del Web. Hola a todos: Quiero montar en un pequeño sitio unos tabs pero no consigo que este código que encontré en internet conmute y muestre el ...
  #1 (permalink)  
Antiguo 27/05/2011, 15:04
 
Fecha de Ingreso: abril-2011
Mensajes: 41
Antigüedad: 13 años
Puntos: 0
No consigo cambiar de tab

Hola a todos:

Quiero montar en un pequeño sitio unos tabs pero no consigo que este código que encontré en internet conmute y muestre el contenido de los demás tabs. Siempre está activo el primer tabs. Cuando doy un click sobre cualquiera de los tabs va hacia un enlace que está fuera y nunca me activa ese tab y más que todo necesito que muestre el contenido (body) del tab correspondiente.

¿Cuál es la parte del código que determina la conmutación entre los tabs?

Para no hacer muy largo este hilo no he colocado el archivo .css, el cuál muestra correctamente los tabs.

El archivo Static_Tabstrip.php

Código PHP:
Ver original
  1. <?php
  2.     /**
  3.     * o------------------------------------------------------------------------------o
  4.     * | This package is licensed under the Phpguru license. A quick summary is       |
  5.     * | that for commercial use, there is a small one-time licensing fee to pay. For |
  6.     * | registered charities and educational institutes there is a reduced license   |
  7.     * | fee available. You can read more  at:                                        |
  8.     * |                                                                              |
  9.     * |                  http://www.phpguru.org/static/license.html                  |
  10.     * o------------------------------------------------------------------------------o
  11.     *
  12.     */
  13.  
  14.     /**
  15.     * Produces a tab strip
  16.     *
  17.     * NB: Don't forget the CSS styles
  18.     *
  19.     * @param array $tabs Multi dimensional array of tabs. First dimension is
  20.     *                    numerically indexed, second has the following keys:
  21.     *                     o link   -  The link used
  22.     *                     o name   -  The text used inside the link which the user sees
  23.     *                     o active -  Whether this tab is active or not. Naturally only
  24.     *                                 one tab should have this set to true...
  25.     */
  26.     function PrintTabStrip($tabs, $leader = null)
  27.     {
  28.         ?>
  29.             <div class="tabstrip">
  30.                 &nbsp;
  31.                 <?foreach($tabs as $t):?>
  32.                     <div class="tabstrip_tab <?=($t['active'] ? 'active' : '')?>" id="<?=$t['id']?>">
  33.                         <?if(!$t['active']):?>
  34.                             <img src="images/tab_tl.png" style="position: absolute; top: -1px; left: -1px" width="5" height="5" />
  35.                             <img src="images/tab_tr.png" style="position: absolute; top: -1px; right: -1px" width="5" height="5" />
  36.                         <?else:?>
  37.                             <img src="images/tab_active_tl.png" style="position: absolute; top: -1px; left: -1px" width="5" height="5" />
  38.                             <img src="images/tab_active_tr.png" style="position: absolute; top: -1px; right: -1px" width="5" height="5" />
  39.                         <?endif?>
  40.                        
  41.                         <?if(!empty($t['link'])):?><a href="<?=$t['link']?>" <?if(!empty($t['mouseover'])):?>onmouseover="window.status = '<?=$t['mouseover']?>'; return true" onmouseout="window.status = ''"<?endif?>><?=$t['name']?></a><?else:?><?=$t['name']?><?endif?>
  42.                     </div>
  43.                 <?endforeach?>
  44.                 &nbsp;
  45.             </div>
  46.         <?php
  47.     }
  48. ?>



Código PHP:
Ver original
  1. <?php
  2.   /**
  3.   * Include the tabstrip code
  4.   */
  5.   require_once('Static_Tabstrip.php');
  6.  
  7.   /**
  8.   * Define the tabs by using a two dimensional array
  9.   */
  10.   $tabs = array(
  11.          array('id' => 'tab_1', 'name' => 'First tab', 'active' => empty($_GET['tab']), 'link' => 'example.php', 'mouseover' => 'Visit Google!'),
  12.          array('id' => 'tab_2', 'name' => 'Second', 'active' => !empty($_GET['tab']) && $_GET['tab'] === '2', 'link' => 'example.php?tab=2', 'mouseover' => 'Or not...'),
  13.          array('id' => 'tab_3', 'name' => 'Third (disabled)', 'active' => false)
  14.          );
  15.  
  16.   PrintTabStrip($tabs);
  17. ?>

Código HTML:
Ver original
  1. <div class="tab_body">
  2.   <?if(empty($_GET['tab'])):?>
  3.     <h1>Some content</h1>
  4.  
  5.     <p>
  6.       Put the main content in here
  7.     </p>
  8.   <?elseif($_GET['tab'] == 2):?>
  9.     <h1>More content</h1>
  10.  
  11.     <p>
  12.       Put more content in here. Use seperate files for better organisation.
  13.     </p>
  14.   <?endif?>
  15. </div>


Muchas gracias me pueden ayudar?, porfa
  #2 (permalink)  
Antiguo 27/05/2011, 16:39
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: No consigo cambiar de tab

Tu problema no es realmente de PHP, sino de Javascript (creo), por lo que la unica sugerencia que te puedo hacer es que no uses short_tags <? y en su lugar uses la etiqueta completa <?php
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 27/05/2011, 17:08
 
Fecha de Ingreso: abril-2011
Mensajes: 41
Antigüedad: 13 años
Puntos: 0
Respuesta: No consigo cambiar de tab

Probé con javascript pero al tener 8 tabs con mucho contenido y tablas cuando cargo la página en el navegador despliega primeramente todo el contenido de los tabs verticalmente durante unos 9 seg.
y luego es que muestra los tabs correctamente, además hay funciones javascript de validaciones. Con javascript es un desastre.
  #4 (permalink)  
Antiguo 27/05/2011, 19:14
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: No consigo cambiar de tab

Bueno, para resolver el problema de que se muestren todos al principio, con CSS puedes aplicar opciones de visualizacion inicial a cada cosa, flotar, ocultar, etc.

Si quieres hacerlo directamente con PHP sera recargando toda la pagina y lo unico que necesitarias es validar el tab actual:

Código PHP:
Ver original
  1. // Asignas desde GET o con valor por default
  2. $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 0;
  3.  
  4. // Verificas que realmente existe el tab
  5. if( ! isset($tabs[$tab])) {
  6.     $tab = 0;
  7. }
  8.  
  9. // Ya cuando vayas a mostrar el contenido:
  10. if($tab == 0) {
  11.     // Contenido del primer tab (cero)
  12. } else if($tab == 1) {
  13.     // Contenido de otro tab
  14. } else if($tab == 10) {
  15.     // Contenido de otro tab
  16. }
__________________
- León, Guanajuato
- GV-Foto
  #5 (permalink)  
Antiguo 28/05/2011, 13:13
 
Fecha de Ingreso: abril-2011
Mensajes: 41
Antigüedad: 13 años
Puntos: 0
Respuesta: No consigo cambiar de tab

Muchas gracias.

Etiquetas: tab
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:30.