Passing Hidden Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gmitra
Forum Newbie
Posts: 15
Joined: Tue Jul 02, 2002 7:45 pm
Location: New York

Passing Hidden Variables

Post by gmitra »

I need help in passing hidden variables. I'd like to know how to correctly incorporate

Code: Select all

<input type="hidden" name="my_var" value="<?php echo $my_var ?>">


(my_var being any variable that it should be called to make this thing work) into my php script...

Code: Select all

<!--begin order--> 

<form name="order"> 

<font face="verdana" size="2">Sort By </font> 

   <select size="1" name="category" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" onChange="location=document.order.category.options&#1111;document.order.category.selectedIndex].value;" value="GO"> 

   <option>---------------</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=date&how=desc">Date (DESC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=date&how=asc">Date (ASC)</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=name&how=asc">Title (ASC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=name&how=desc">Title (DESC)</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=category&how=asc">Category (ASC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=category&how=desc">Category (DESC)</option> 

        </select> 

</form> 

<!--end order--> 

   </td> 
   <td align="left" width="408"> 

<!--begin search--> 

<FORM METHOD="post" ACTION="http://localhost/george/articles/index.php"> 

<font size="2" face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<input type="submit" value="Title Search" name="Title Search" style="font-size: 7pt; font-family: Verdana; border-style: solid; border-width: 1">&nbsp; </font>

<input type="text" name="search" size="30" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1">

</form>

<!--end search-->
So that my $search variable will continue to be passed on from page to page. This way my users can easily sort their search results without losing the $search variable. I'm really having trouble trying to pass my users search query from page to page... please help!
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post by EricS »

It appears you have two forms in the script and not one. The two will operate independant of each other. That is why the search value isn't being passed, because the browser is disregarding the all the values in the first form and only submitting the values in the second form. Try this out.

Code: Select all

<!--begin order--> 

<FORM name="order" METHOD="post" ACTION="http://localhost/george/articles/index.php"> 

<font face="verdana" size="2">Sort By </font> 

   <select size="1" name="category" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1" onChange="location=document.order.category.options&#1111;document.order.category.selectedIndex].value;" value="GO"> 

   <option>---------------</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=date&how=desc">Date (DESC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=date&how=asc">Date (ASC)</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=name&how=asc">Title (ASC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=name&how=desc">Title (DESC)</option> 
        <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=category&how=asc">Category (ASC)</option> 
   <option value="?id=results2&search=<?=$_POST&#1111;'search']?>&order=category&how=desc">Category (DESC)</option> 

        </select> 

<!--end order--> 

   </td> 
   <td align="left" width="408"> 

<!--begin search--> 

<font size="2" face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<input type="submit" value="Title Search" name="Title Search" style="font-size: 7pt; font-family: Verdana; border-style: solid; border-width: 1">&nbsp; </font> 

<input type="text" name="search" size="30" style="font-family: Verdana; font-size: 8pt; border-style: solid; border-width: 1"> 

</form> 

<!--end search-->
User avatar
gmitra
Forum Newbie
Posts: 15
Joined: Tue Jul 02, 2002 7:45 pm
Location: New York

Post by gmitra »

Doing that just messes up my layout and doesn't work either. In the way I wrote above I was able to search and sort the search listings one time. But if I tried sorting the listings again the browser kinds of "forgets" the previous query and instead of sorting out the search results, sorts out everything in the database.

EDIT: The problem has been resolved thanks to everyone that has helped.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Always nice to tell people how a particular problem was solved...

Mac
User avatar
gmitra
Forum Newbie
Posts: 15
Joined: Tue Jul 02, 2002 7:45 pm
Location: New York

Post by gmitra »

Sorry,

I added...

Code: Select all

<?php

$searchParameters = ( isset($_POST&#1111;'search']) ) ? $_POST&#1111;'search'] : $_GET&#1111;'search'];

?>
above the drop down menu and changed $_POST['search'] to

Code: Select all

<?=$searchParameters?>
The problem seemed to lay in that after the first sort it was no longer $_POST, but $_GET. Adding that small code on top lets the browser decide which one it was. -- This resolution came from mordred on Coding Forums.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Thank you.

Mac
Post Reply