Solved

Passing a variable value to query string using a hidden field

Posted on 2008-06-13
7
1,492 Views
Last Modified: 2013-12-13
I have a variable name $vars where I am saving all the variables such as:
if($publish_year) $vars .= "&year=".$publish_year;

and then passing it through a form as following:
<input id="vars" name="vars" value="<? echo $vars; ?>" type="hidden" />
<label for="perPage">Number</label>
          <select id="perPage" name="perPage">
            <option value="10"<? if($_GET['perPage'] == '10'){ ?> selected="selected"<? } ?>>10</option>
            <option value="25"<? if($_GET['perPage'] == '25'){ ?> selected="selected"<? } ?>>25</option>
            <option value="50"<? if($_GET['perPage'] == '50'){ ?> selected="selected"<? } ?>>50</option>  
            <option value="100"<? if($_GET['perPage'] == '100'){ ?> selected="selected"<? } ?>>100</option>
          </select>


The output in the query string shows all % % why is that?
here's the output

www.mytestwebsite.php?order_by=Date+DESC&vars=%26year%3D2000&perPage=25
Technicall I should have year=2000

any ideas?
thanks

0
Comment
Question by:martyje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 21779835
You are looking at URL-encoded strings when you see those % signs
0
 

Author Comment

by:martyje
ID: 21780223
How do I get rid of them?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 21781281
Good question!  Something is "helping" you by url-encoding things in your form.  Hex 26 is an ampersand and hex 3D is an equal sign.  If you can post the PHP that generates the link, I may be able to pick up the point.  Or you can look at the PHP function urldecode() and it may be just what you need once you get the hidden string back into your script.  ~Ray
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:martyje
ID: 21875935
This is how I resolved the issue:

$body = ereg_replace("\n|<p>|</p>", "%0A", "Title: ". $title. "</p><p>". "Published Date: ". $publish_date. "
                                      </p>");
$contact_email=  "<a href=\"mailto:$contact_data?subject=Test%20Email&amp;body=$body\">$contact_data</a>";
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 21876056
Just wondering, did you try the urldecode() function?
0
 

Author Comment

by:martyje
ID: 21876071
Yes I did. That didn't work.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 21876267
Hmm.  It worked perfectly for me.  Here is the script I used to test it before posting the answer.

You can run that script here:
http://www.laprbass.com/RAY_urldecode.php

I copied your example with cut-and-paste, ran it through urldecode() and got this output, which is correct:
www.mytestwebsite.php?order_by=Date DESC&vars=&year=2000&perPage=25

Can you please post the output from your test that didn't work?
<?php
 
if ($_GET["q"] == "d") {
  $script  = $_SERVER["SCRIPT_FILENAME"];
  $string = file_get_contents($script);
  header("Content-type: text/plain");
  header("Content-disposition: attachment; filename=\"" . $script . "\";" );
  echo $string;
  flush();
} else {
  echo "<br /><strong>Here is the output of urldecode()</strong>\n";
  echo "<br />\n";
  echo urldecode("www.mytestwebsite.php?order_by=Date+DESC&vars=%26year%3D2000&perPage=25");
  echo "<br /><br /><a href=\"$PHP_SELF?q=d\">To download the contents of this script, click here</a>\n";
}
die();
?>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question