Page 1 of 1

Passing Hidden Variables

Posted: Sat Aug 03, 2002 8:15 pm
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!

Posted: Sun Aug 04, 2002 12:36 am
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-->

Posted: Sun Aug 04, 2002 8:54 am
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.

Posted: Sun Aug 04, 2002 5:10 pm
by twigletmac
Always nice to tell people how a particular problem was solved...

Mac

Posted: Sun Aug 04, 2002 5:16 pm
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.

Posted: Sun Aug 04, 2002 5:18 pm
by twigletmac
Thank you.

Mac