Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing a variable value to query string using a hidden field

Posted on 2008-06-13
7
Medium Priority
?
1,499 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
  • 4
  • 3
7 Comments
 
LVL 111

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 111

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
Technology Partners: 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

877 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