Home » HTML » Pager » Bug #3878
POST method support
Details
| Request #3878 | POST method support |
|---|---|
| Submitted | 2005-03-19 02:59 UTC |
| From | otto at atrus dot org |
| Assigned | quipo |
| Status | Closed |
| Package | Pager |
| PHP Version | 5.0.3 |
| OS | N/A |
| Roadmaps | (Not assigned) |
Comments
[2005-03-19 02:59 UTC] otto at atrus dot org
Description:
------------
This patch introduces POST method support via onclick JavaScript. The generated JavaScript generates a form element, adds hidden inputs with keys and values, and submits it. It uses only local variables, so it shouldn't affect other code on the page. The only browser prerequisite is basic DOM compliance (specifically, document.createElement, document.getElementsByTagName, and node_foo.appendChild). It has been tested in IE6 and Firefox 1.0.1 so far.
It also includes some of my previously suggested changes, more for sanity than anything else. Specifically, this includes:
* #3450 - Use $_GET instead of reparsing
* #3449 - Exclude query vars entirely
* #3451 - Use http_build_query
It now has a dependency on PHP_Compat for PHP versions < 5
New options include:
* httpMethod (string): Specifies the HTTP method to use. Valid values are GET or POST
* importQuery (bool): if true (and it is by default), varibles and values are imported from the submitted data (query string) and used in the generated links
Both default to BC values (GET and true, respectively).
I have attempted to maintain the same style as the rest of the code and add documentation for everything I've added.
This patch has only been lightly tested and should be considered beta-quality at the moment. I hope it proves useful.
Reproduce code:
---------------
require_once 'Pager/Pager.php';
echo '<pre>';
$params = array(
'mode' => 'Jumping',
'httpMethod' => 'POST',
'perPage' => 3,
'delta' => 2,
'itemData' => array('a','b','c','d','e','f','g','h','i','j','k','...', 'z')
);
$pager = & Pager::factory($params);
$data = $pager->getPageData();
$links = $pager->getLinks();
//$links is an ordered+associative array with 'back'/'pages'/'next'/'first'/'last'/'all' links.
//NB: $links['all'] is the same as $pager->links;
//echo links to other pages:
echo $links['all'];
//Pager can also generate <link rel="first|prev|next|last"> tags
echo $pager->linkTags;
//Show data for current page:
echo 'PAGED DATA: ' ; print_r($data);
//Results from methods:
echo 'getCurrentPageID()...: '; var_dump($pager->getCurrentPageID());
echo 'getNextPageID()......: '; var_dump($pager->getNextPageID());
echo 'getPreviousPageID()..: '; var_dump($pager->getPreviousPageID());
echo 'numItems()...........: '; var_dump($pager->numItems());
echo 'numPages()...........: '; var_dump($pager->numPages());
echo 'isFirstPage()........: '; var_dump($pager->isFirstPage());
echo 'isLastPage().........: '; var_dump($pager->isLastPage());
echo 'isLastPageComplete().: '; var_dump($pager->isLastPageComplete());
echo '$pager->range........: '; var_dump($pager->range);
echo "\$_POST = \n";
print_r( $_POST );
echo "\n\$_GET = \n";
print_r( $_GET );
echo '</pre>';