Solved

Passing a variable value to query string using a hidden field

Posted on 2008-06-13
7
1,490 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 109

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 109

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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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 109

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 109

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

773 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