Pass Variable On Click Of Button

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
ridgedale
Forum Newbie
Posts: 5
Joined: Tue Mar 06, 2007 8:16 am

Pass Variable On Click Of Button

Post 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.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Try keeping your session variable into HIDDEN field. e.g.

Code: Select all

<input type='HIDDEN' name='session_var' value='$session_var'>
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

what do you mean by: "default registration username and password"??
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do you have to use a button for the register action? Why can't you use a link?
ridgedale
Forum Newbie
Posts: 5
Joined: Tue Mar 06, 2007 8:16 am

Post 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?
Post Reply