Page 1 of 1
Pass Variable Using Buttons
Posted: Sun Jul 15, 2007 4:30 am
by ridgedale
I am trying to pass a variable (say $name for the sake of this example) from one page to another using buttons only. I have 2 buttons Login and Register. When the user clicks on Login I would like $name to be set to "login" and when the user clicks on Register $name should be set to "register". This is so I can direct the user to the right login/register form.
Is this possible? If so, could some kind person provide an example?
Many thanks in advance.
Posted: Sun Jul 15, 2007 4:38 am
by idevlin
Put one form around the login button, complete with your $name variable, and another form around the register button, with the $register variable.
Posted: Sun Jul 15, 2007 5:15 pm
by ridgedale
Thanks for your reply, idevlin.
I'm not sure I understand what you mean by putting a form around a button. Could you please provide an example of what you mean?
I think I may not quite have explained properly what I am trying to achieve. Hopefully what I have outlined below describes more clearly what I am aiming for:
The 1st page the user goes to is a welcome page (welcome.php) asking the user if they are an existing subscriber who has already registered or a new subscriber who needs to register.
There are only two pages involved: welcome.php and target.php. There is no form on the welcome page (welcome.php). The login form - to be controlled by an if statement - is on the target page (target.php).
If the user is an existing subscriber they are to click on the login button which will take them to target.php where they can complete their user name and password entries into the fields provided so they can enter the database.
If the user is a new subscriber they are to click on the register button which will also take them to target.php where the default new subscriber login username and password will be pre-entered allowing them to log into the database in order to complete their registration from where they are passed out of the database on successful completion of their registration to await their username and password details.
Thanks again for your help.
Posted: Sun Jul 15, 2007 5:39 pm
by ridgedale
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I think I have managed to solve this by using the following code as an example. If anyone has thoughts on if or how this can be improved upon I would be grateful for any input.
welcome.php:
[syntax="html"]<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="welcome"><h1>Welcome Everyone!</h1><br />
</div>
<div id="navbar">
<ul>
<li><a href="target.php?name=login">Login</a></li>
<li><a href="target.php?name=register">Register</a></li>
<li><a href="http://www.google.com">Cancel</a></li>
</ul>
</div>
</body>
</html>
target.php:[/syntax]
Code: Select all
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
$name = $_REQUEST['name'];
if ($name == 'login') {
echo "Welcome to WebWorld, $name!";
} else {
echo "You will need to complete the registration form, $name!";
}
?>
</body>
</html>
Many thanks again.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]