How to stop a form URL encoding stuff.

GeX

GeX

Soldato
Joined
17 Dec 2002
Posts
6,982
Location
Manchester
I have a drop down box on a page, it is for changing page numbers. atm I just pass in number for the page,

http://www.foo.com/bar.php?page=1

However, I need to now filter this

http://www.foo.com/bar.php?page=1&id=1

Whenever I try and add 'id=1' to the select on the form, it URL encodes it and then the link doesn't seem to work.

Code:
<form style="display:inline;margin:0px" name="fPage" id="fPage" method="get" action="<?=$PHP_SELF?>"><div class="bar">
    <?=pixel_text("black", "page ")?>
    <select onchange="document.fPage.submit();" name="page" style="width:45px; height:17px;">
      <?php
	for($i=1;$i<=$userPageCount;$i++) {
		if($i==$userPageNumber) $selected = "selected"; else $selected = "";
?>
      <option value="<?=$i?>" <?=$selected?>>
      <?=$i?>
      </option>
      <?php
	}
?>
    </select>
    <?=pixel_text("black", " of " . $userPageCount)?>
</div></form>

Need to add some more to the page it loads, so changed

<option value="<?=$i?>" to <option value="<?=$i . "?id=" . $id?>"

But ? and = come out as URL encoded, and the link fails.

I would've thought it would work as URL encoded anyway.. as it's going in as a URL?

me foncused!
 
What you need to do is add a hidden field to your form which contains the ID. Adding special characters to field values using the querystring will result in encoding - as you've seen.

The below should work for you:
Code:
<form style="display: inline; margin: 0px" name="fPage" id="fPage" method="get" action="<?= $PHP_SELF ?>">
	<div class="bar">
		<?= pixel_text("black", "page ") ?>
		<select onchange="document.fPage.submit();" name="page" style="width:45px; height:17px;">
			<?php for($i = 1; $i <= $userPageCount; $i++) {
				$selected = ($i == $userPageNumber) ? "selected" : ""; ?>
				<option value="<?= $i ?>" <?= $selected ?>>
					<?= $i ?>
				</option>
			<?php } ?>
		</select>
		[b]<input type="hidden" name="id" value="<?= $id ?>" />[/b]
		<?= pixel_text("black", " of " . $userPageCount) ?>
	</div>
</form>
 
Last edited:
Back
Top Bottom