Page 1 of 1

Pass Variable On Click Of Button

Posted: Wed Mar 07, 2007 4:29 am
by ridgedale
I'm wondering if anyone might be able to help explain how I can pass a variable (session?) from one page to another on the click of a button.
What I have is the main webpage with 2 buttons - Login and Register. When the user clicks on either button at present they are taken to the same login webpage where they can fill in their login details. The problem with this is that users who need to register do not read the accompanying text which gives the default registration username and password so they can login and complete the registration form in the backend database.
What I would like to achieve is that when a user clicks on the register button the default registration username and password are passed to the next page and automatically entered into the relevant fields so the user only has to click on the Login button on that page.
I presume that I need to start the session on the first page and set the variables ($uname and $pwd) somehow when the user clicks on the register button and then pass the contents of the variable to the next page where I can transfer the contents into the relevant fields automatically using an If statement. Could someone please explain how I achieve this?
Would I also be right in assuming that it would be a good idea to clear the variables when the user clicks on the Login button on the second page?
Any assistance with this would be greatly appreciated.

Posted: Wed Mar 07, 2007 6:08 am
by amir
Try keeping your session variable into HIDDEN field. e.g.

Code: Select all

<input type='HIDDEN' name='session_var' value='$session_var'>

Posted: Wed Mar 07, 2007 7:53 am
by Begby
How about on the 2nd page you just check to see what button they clicked. If they clicked register you fill in the default values with php as you build the response, otherwise leave them blank. This will eliminate having to pass data between the two pages.

Posted: Wed Mar 07, 2007 10:46 am
by Kieran Huggins
what do you mean by: "default registration username and password"??

Posted: Wed Mar 07, 2007 11:53 am
by RobertGonzalez
Do you have to use a button for the register action? Why can't you use a link?

Posted: Thu Mar 08, 2007 9:16 am
by ridgedale
Thanks for your responses everyone.

Begby, I think what you are suggesting is probably a more elegant and simpler way to deal with the problem.

My question is: How do I achieve what you are suggesting? i.e. how do I get the second page to track which button has been clicked on?