开发者

html selection list using GET method while keeping previous URL variables set

is there a way of using the GET method to send variables via URL from a selection list, but keeping the current variables in the URL intact???

Because I have a selection list and I used to select one of those to bring up a new league table using the POST method, but because I have pagination when I click on the links to go to the next page and so on, it refreshes and it loses the POST from the Selection and just shows the league table again as the default selection in the list and not the one that I selected originally. So how would I go about using the GET method for this, but so I can keep the variables currently set in the URL aswel. As when I try to use the GET method it removes the other variables in the URL and only sends the variable from the selection list.

 echo "<form method=\"POST\" action=\开发者_如何学C"\">
 Rankings after the<SELECT NAME=\"rankingsfrom\">$options1</SELECT>
 <input type=\"submit\" value=\"Go\"/></form>";


You can have hidden type inputs in the same form. If you want to keep page number, you can retrieve it and put it in something like:

echo "<form method=\"POST\" action=\"\">
 Rankings after the<SELECT NAME=\"rankingsfrom\">$options1</SELECT>
 <input type=\"hidden\" name=\"pageNumber\" value=\"$page_number\" />
 <input type=\"submit\" value=\"Go\"/></form>";

Then when you post it, you can retrieve the page number with $_POST['pageNumber']


You can pass some $_GET variables in the action like:

?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?var1=<?php echo $_GET['var1']?>&var2=<?php echo $_GET['var2'] ?>">
<?php

or you could pass the pagination as a $_POST variable. Set your pagination to accept $_GET['page_number'] or $_POST['page_number'] like:

if(isset($_GET['page_number']) && !empty($_GET['page_number']))
{
  $page_number = $_GET['page_number'];
}
elseif(isset($_POST['page_number']) && !empty($_POST['page_number']))
{
  $page_number = $_POST['page_number'];
}
else
{
  $page_number = 1;
}


If you are using server side scripting, assuming the data you are passing is not open to attack, you could populate hidden form elements with it which would be available next time you do a post.


Well, technically you don't have to worry about that. If you have:

page.php?x=abc&y=zxc&x=qwe

When you run that page, the variable x has a value of qwe because the latest one on the GET string is used and overwrites the previous one. This isn't necessarily clean, but I use this all the time and I've seen others use it as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜