This topic is locked

User selectable dropdown after login

9/28/2013 19:00:25
PHPRunner General questions
bbarker author

What's the easiest way to have a user select from a dropdown list after they log in, so that I can use it as a Session variable?

(A Button on the Menu page??)
Example:

User logs in. They belong to 5 GROUPS in the Group_table.
The MENU page has a list of reports --- But it also includes a BUTTON so that the user can select their GROUP AFFILIATION.
Once they <a> click the button, and <b> select the GROUP, <c> it saves it to a Session Variable.
Then all futher selections off the MENU can use the Session variable.

Sergey Kornilov admin 9/29/2013

Yes, I guess you can add a dropdown box and a button to the menu page and save selected value to the session variable in button's OnServer code.

bbarker author 9/30/2013

This is taking much longer that I thought it would.
On this page, should the circled word ALSO be ? (argggghh...) <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=72176&image=1&table=forumreplies' class='bbc_emoticon' alt=':blink:' />
----------------------------------------------------------------




Page 265 in the PHP 6.2 Manual

Sergey Kornilov admin 10/1/2013

Yes, "company" needs to be replaced with the actual field name. I have to add that this sample code provides very little help here as it redirects user to another page while your requirement to save selected value in session variable. You will need a button and a custom dropdown box.

  1. In ClientBefore event get the current selected value of dropdown box and pass it to server event
  2. OnServer event - save that value to session variable
  3. ClientAfter event - redirect user to another page if required

bbarker author 10/1/2013



Yes, "company" needs to be replaced with the actual field name. I have to add that this sample code provides very little help here as it redirects user to another page while your requirement to save selected value in session variable. You will need a button and a custom dropdown box.

  1. In ClientBefore event get the current selected value of dropdown box and pass it to server event
  2. OnServer event - save that value to session variable
  3. ClientAfter event - redirect user to another page if required


Yes... Thanks... I spent a long time before I saw the "missed" highlight.

I'm still struggling with 1 and 2 above.
Trying to use this to get the value (1).

RETAIN THE SELECTION>>

while ($data = db_fetch_array($rs)) { if ($data["ProductID"]==$_SESSION["CurrentProduct"]) $selected = " selected";

else $selected = " ";

$str.="<option value=\"orders_tbl_list.php?a=search&value=1&SearchFor=".$data["ProductID"].

"&SearchOption=Contains&SearchField=Selected_Product\"".$select.">".$data["Product_Name"]."</option>";}


and this to save the variable (2)

$_SESSION["idregion"] = $data["id_rgn"];
bbarker author 10/2/2013

Well, I just can't quite make it work. I'm getting messed up going between the Client BEFORE and the ONSERVER events.

I gave up using a button and went back to creating a new page with an EDIT dropdown.
[size="5"]Does anyone have a simple example of how to save a DROPDOWN selection to a $_SESSION variable?

[/size]
Or can you point me to one? I've looked through all of the Manual, the Tutorials and many, many Google searches. The cross-environment (PHP, JavaScript (JQuery), etc) is throwing me.
Yes... I'm a man.... and I'm asking for directions!!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=72193&image=1&table=forumreplies' class='bbc_emoticon' alt='B)' />

Sergey Kornilov admin 10/2/2013

You are asking for directions to the place that don't exist yet. Lets start by posting the following:

  1. Code that displays the dropdown
  2. Your ClientBefore code
  3. Your OnServer code
    It also will be helpful if you explain what exactly causes the trouble.
    If you simply insert a new button somewhere you can see the sample code in there.

    ClientBefore: we assign value to parameter named "txt"

    params["txt"] = "Hello";
    OnServer: we do something with parameter named "txt"

    $result["txt"] = $params["txt"]." world!";
    This is how we pass data between client and server part.
    Yes, this is a mix of PHP and Javascript. This is how web applications work.

bbarker author 10/2/2013



This is how we pass data between client and server part.

Yes, this is a mix of PHP and Javascript. This is how web applications work.



Understand and I have no issue with that. It's using field names in place of text that I can't seem to comprehend.
Yes, I have tested the button feature and it works good when using "txt" to print "Hello World".
I'm trying to use a dropdown selection and have it save the selection to a Session variable.



So if a dropdown box displays from $data["numberlisting"]:

One

Two

Three
and I click on "Two",
then I want to invoke the following:

$_Session["Number"] = $data["numberlisting"] for the selected record.
Where do I add this equation?


Here's my difficulty with the "txt" example.



ClientBefore: we assign value to parameter named "txt"

params["txt"] = "Hello";

Do I substitute $data["numberlisting"] for "Hello"???



OnServer: we do something with parameter named "txt"

$result["txt"] = $params["txt"]." world!";

And, do I substitute $_Session["Number"] for $result["txt"]???
A simple example using fake $data values would be helpful. I'm hung up with trying to get the "txt" example to map to the variables.

Sergey Kornilov admin 10/2/2013

It just doesn't work this way. On the client side (ClientBefore event) you do not have access to any PHP variables like $data["numberlisting"]. You need to use Javascript to get the value of selected dropdown item and pass it to the server side.
Here is your sample code to get the text of selected dropdown box option:

http://stackoverflow.com/questions/6454016/get-text-of-the-selected-option-wth-jquery

(Google "jquery get selected option text" for more examples)
You will have to modify sample code to match the ID of the dropdown box you build manually and this why you need to post the exact code that builds the dropdown box.