Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]$_GET po odbieraniu formularza $_POST
Forum PHP.pl > Forum > Przedszkole
SoSiker
Hej, mam pytanie:

Dlaczego po wprowadzeniu danych przez formularz typu $_POST nie mogę kliknąć na żaden link z $_GETem? Tzn. mogę ale wywala mnie do głównej strony aplikacji.

Jak mogę to obejść?? Mam nadzieję, że ktoś mnie zrozumiał smile.gif
wookieb
Jakbyś sypnął garść kodu to byłoby lepiej ci pomóc ;>
zordon
jeśli Cię dobrze zrozumiałem, to chodzi o to, że pewnie masz 'action' formularza ustawiony na stronę główną, np 'index.php' a nie 'index.php?akcja=action'

po wysłaniu formularza tracisz wtedy wszystkie dane z $_GET.
erix
Cytat
Dlaczego po wprowadzeniu danych przez formularz typu $_POST nie mogę kliknąć na żaden link z $_GETem? Tzn. mogę ale wywala mnie do głównej strony aplikacji.

Bo link nie jest formularzem. ;]

Jeśli chcesz, aby te dane pozostały, to przy pierwszym wywołaniu wrzucaj je do sesji.
SoSiker
Klasa, z której korzystam do paginacji smile.gif zapomniałem jeszcze powiedzieć, że używam smartów

class pagination
{
var $page = 1; // Current Page
var $perPage = 10; // Items on each page, defaulted to 10
var $showFirstAndLast = false; // if you would like the first and last page options.

function generate($array, $perPage = 10,$page)
{
// Assign the items per page variable
if (!empty($perPage))
$this->perPage = $perPage;
$_GET['page'] = $page;
// Assign the page variable
if (!empty($_GET['page'])) {
$this->page = $_GET['page']; // using the get method
} else {
$this->page = 1; // if we don't have a page number then assume we are on the first page
}

// Take the length of the array
$this->length = count($array);

// Get the number of pages
$this->pages = ceil($this->length / $this->perPage);

// Calculate the starting point
$this->start = ceil(($this->page - 1) * $this->perPage);

// Return the part of the array we have requested
return array_slice($array, $this->start, $this->perPage);
}

function links()
{
// Initiate the links array
$plinks = array();
$links = array();
$slinks = array();

// Concatenate the get variables to add to the page numbering string
if (count($_GET)) {
$queryURL = '';
foreach ($_GET as $key => $value) {
if ($key != 'page') {
$queryURL .= '&'.$key.'='.$value;
}
}
}

// If we have more then one pages
if (($this->pages) > 1)
{
// Assign the 'previous page' link into the array if we are not on the first page
if ($this->page != 1) {
if ($this->showFirstAndLast) {
$plinks[] = ' <a href="?page=1'.$queryURL.'">&laquo;&laquo; Pierwsza </a> ';
}
$plinks[] = ' <a href="?page='.($this->page - 1).$queryURL.'">&laquo; Wstecz</a> ';
}

// Assign all the page numbers & links to the array
for ($j = 1; $j < ($this->pages + 1); $j++) {
if ($this->page == $j) {
$links[] = ' <a class="selected">'.$j.'</a> '; // If we are on the same page as the current item
} else {
$links[] = ' <a href="?page='.$j.$queryURL.'">'.$j.'</a> '; // add the link to the array
}
}

// Assign the 'next page' if we are not on the last page
if ($this->page < $this->pages) {
$slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Nastepna &raquo; </a> ';
if ($this->showFirstAndLast) {
$slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Ostatnia &raquo;&raquo; </a> ';
}
}

// Push the array into a string using any some glue
return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
}
return;
}
}


$user.class->editUser($_POST);
$users = $user.class->getUsers();
$users = $pagination1->generate($users, 10,$_POST['page']);
$smarty->assign('pagination', $pagination->links());
$smarty->assign('get',$_POST);
$smarty->assign('users',$users);
$smarty->display('users.tpl');
zordon
jeśli chodzi o to, że nie działają ci linki paginacji to dodaj:

SmartyPaginate::setUrl('twoje_url_z_get', $pagination_id);

'twoje_url_z_get' moze wygladac np tak: 'index.php?id_k='.$id_k

przy okazji mała wskazówka - ZAWSZE używaj id_paginacji - u mnie $pagination_id, bo paginacje będa ci się gryzły ze soba jesli np zechcesz uzyc jej w innym miejscu lub nawet innym projekcie(lub nawet bedziesz mial otwarta strone ktora paginacji uzywa)
SoSiker
Nie mam takiej klasy jak SmartyPagination smile.gif to nie chodzi o to, tylko o przejście z $_POST na $_GET, niby link robi się dobry ale po kliknięciu w nr strony nie przezuca dobrze :/
Spawnm
SoSiker daj kod w bbcode i zrób wcięcia , łatwiej będzie to ogarnąć smile.gif
SoSiker
Wiadomo na początku includuje plik z klasa
Pilk wykonywujący:

  1. <?php
  2. elseif (isset($_POST['editUser']))
  3. {
  4.     $user.class->editUser($_POST);
  5.     $users = $user.class->getUsers();
  6.     $users = $pagination->generate($users,10,$_POST['page']);
  7.     $smarty->assign('pagination', $pagination->links());
  8.     $smarty->assign('page',$_POST['page']);
  9.     $smarty->assign('get',$_POST);
  10.     $smarty->assign('users',$users);
  11.     $smarty->display('users.tpl');
  12. }
  13. ?>

Plik zawierający klasę pagination
  1. <?php
  2. class pagination
  3.  {
  4.    var $page = 1; // Current Page
  5.    var $perPage = 10; // Items on each page, defaulted to 10
  6.    var $showFirstAndLast = false; // if you would like the first and last page options.
  7.    
  8.    function generate($array, $perPage = 10,$page)
  9.    {
  10.      // Assign the items per page variable
  11.      if (!empty($perPage))
  12.        $this->perPage = $perPage;
  13.        $_GET['page'] = $page;
  14.      // Assign the page variable
  15.      if (!empty($_GET['page'])) {
  16.        $this->page = $_GET['page']; // using the get method
  17.      } else {
  18.        $this->page = 1; // if we don't have a page number then assume we are on the first page
  19.      }
  20.      
  21.      // Take the length of the array
  22.      $this->length = count($array);
  23.      
  24.      // Get the number of pages
  25.      $this->pages = ceil($this->length / $this->perPage);
  26.      
  27.      // Calculate the starting point
  28.      $this->start  = ceil(($this->page - 1) * $this->perPage);
  29.      
  30.      // Return the part of the array we have requested
  31.      return array_slice($array, $this->start, $this->perPage);
  32.    }
  33.    
  34.    function links()
  35.    {
  36.      // Initiate the links array
  37.      $plinks = array();
  38.      $links = array();
  39.      $slinks = array();
  40.      
  41.      // Concatenate the get variables to add to the page numbering string
  42.      if (count($_GET)) {
  43.        $queryURL = '';
  44.        foreach ($_GET as $key => $value) {
  45.          if ($key != 'page') {
  46.            $queryURL .= '&'.$key.'='.$value;
  47.          }
  48.        }
  49.      }
  50.      
  51.      // If we have more then one pages
  52.      if (($this->pages) > 1)
  53.      {
  54.        // Assign the 'previous page' link into the array if we are not on the first page
  55.        if ($this->page != 1) {
  56.          if ($this->showFirstAndLast) {
  57.            $plinks[] = ' &laquo;&laquo; Pierwsza ';
  58.          }
  59.          $plinks[] = ' page - 1).$queryURL.'&#092;">&laquo; Wstecz ';
  60.        }
  61.        
  62.        // Assign all the page numbers & links to the array
  63.        for ($j = 1; $j < ($this->pages + 1); $j++) {
  64.          if ($this->page == $j) {
  65.            $links[] = ' '.$j.' '; // If we are on the same page as the current item
  66.          } else {
  67.            $links[] = ' '.$j.' '; // add the link to the array
  68.          }
  69.        }
  70.  
  71.        // Assign the 'next page' if we are not on the last page
  72.        if ($this->page < $this->pages) {
  73.          if ($this->showFirstAndLast) {
  74.            $slinks[] = ' pages).$queryURL.'&#092;"> Ostatnia &raquo;&raquo; ';
  75.          }
  76.        }
  77.        
  78.        // Push the array into a string using any some glue
  79.        return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
  80.      }
  81.      return;
  82.    }
  83.  }
  84. ?>


  1. <form action="operator.php" method="GET">
  2. <input type="hidden" name="choice_stat" value="{$choice_stat}" />
  3. </form>
  4. <br />
  5. <hr />
  6. {$komunikat}
  7.  
  8. <div class="span-15">
  9. {if !empty($users)}
  10. {if !empty($pagination)}
  11. {if !empty($page)}
  12. <div class="pagination">{$pagination}</div>
  13. {else}
  14. <div class="pagination">{$pagination}</div>
  15. {/if}
  16. {/if}
  17. <tr><td>l.p.</td><td><b>Imie:</a></b></td><td><b>Nazwisko:</b></td><td><b>Funkcja:</b></td></tr>
  18. {foreach from=$users item=user}
  19. <tr><td><a href="index.php?user_id={$user.id}">{$user.imie}</a></td><td>{$user.nazwisko}</td><td>{$user.funkcja}</td></tr>
  20. {/foreach}
  21. {/if}
  22. </form>


Sory, że dopiero teraz odpowiednio zedytowałem ale musiałem zrobić ręcznie bo coś zautomatu nie wychodziło :/

Podbijam temat smile.gif bo odpowiedzi nie uzyskałem, a na prawdę bardzo mi zależy!! Mam nadzieję, że zostanie wybaczone winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.