...

Passing Hidden Variables

gmitra
08-04-2002, 05:31 AM
Hello, I need help in passing hidden variables. I'd like to know how to correctly incorporate

<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...

<!--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[document.order.category.selectedIndex].value;" value="GO">

<option>---------------</option>
<option value="?id=results2&search=<?=$_POST['search']?>&order=date&how=desc">Date (DESC)</option>
<option value="?id=results2&search=<?=$_POST['search']?>&order=date&how=asc">Date (ASC)</option>
<option value="?id=results2&search=<?=$_POST['search']?>&order=name&how=asc">Title (ASC)</option>
<option value="?id=results2&search=<?=$_POST['search']?>&order=name&how=desc">Title (DESC)</option>
<option value="?id=results2&search=<?=$_POST['search']?>&order=category&how=asc">Category (ASC)</option>
<option value="?id=results2&search=<?=$_POST['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!

Spookster
08-04-2002, 07:41 AM
Hidden input form elements work the same as any other form element. It will get passed to php file that get's called in the action of the form. In your case my_var will get passed as $my_var.

Or did I misunderstand your question?

gmitra
08-04-2002, 02:59 PM
I believe you misunderstood my question. The HTML I wrote above enables the user browsing the site to search and sort the search listings once (it works just one time). But if the user 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. I'm trying to find a way to keep the original query throughout the users sorts so that they can sort their search results more than once.

If it confuses you just minus what I was asking about the hidden input variable. Basically I'm just trying to rewrite or add something to the second script so that the browser doesn't keep "forgetting" the original search query, in this case it would be the $search variable.

mordred
08-04-2002, 03:54 PM
The browser does not forget anything, it's only there to display the result that your PHP script running on the server generated.

I'm afraid your question confuses me a little, but I might help you anyway. From your HTML it looks like you are passing a query string to the same file itself. That's okay so far, only that your query string is constructed with a variable deriving from the $_POST array initially.


<option value="?id=results2&search=<?=$_POST['search']?>&order=date&how=desc">Date (DESC)</option>


When you submit this query string to the file, the "search" variable is no longer in $_POST, but rather in $_GET, since you only called the page by it's URL, not through a form submission.

So you need to check whether "search" is available in the $_POST or $_GET array and apply the correct value in the line above


$searchParameters = ( isset($_POST['search']) ) ? $_POST['search'] : $_GET['search'];


and then you have in your option tags


<option value="?id=results2&search=<?=$searchParameters?>&order=date&how=desc">Date (DESC)</option>


Try that, if it doesn't work, you'll have to post more info about your search routine so we can check where the code chokes.

gmitra
08-04-2002, 04:26 PM
It worked perfectly just like you said! Thanks a lot mordred! :thumbsup:

MarioPro
08-05-2002, 03:30 AM
Hi,

I came to this post to see the solutions here might fit my problem, but, I do have the GET and when the user tries to order the results, the varibles aro no longer there !?

May anyone give alook at my session code to help on this bug please?

Thanks in advance.

The post link:
http://codingforums.com/showthread.php?threadid=3121



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum