Reputation: 11
How can I pass variable from input field to form like this and is it possible?
<form method="POST" action="https://accounts.google.com/o/oauth2/auth?login_hint=<?= $_GET['email']?>" id= "frmTest" name = "frmTest">
<input type="email" id="email" name="email" />
<input type="submit" id="submit" name="submit" />
</form>
Or maybe with javascript somehow? When user fill out that form and click on submit button I want that form redirect him to https://accounts.google.com/ where it will display that email and user will just enter his password
Upvotes: 0
Views: 134
Reputation: 12139
If you use the POST
method in your form, you can't add GET
query parameter in your action
attribute.
In a POST
form these parameters in the action
URL will be discarded. So either send your form as GET
(method="GET"
) and keep the query string as is, or keep it as POST and add the fields in hidden inputs like:
<form method="POST" action="https://accounts.google.com/o/oauth2/auth" id="frmTest" name="frmTest">
<input type="hidden" name="login_hint" value="<?php echo $_GET['email']; ?>" />
<input type="submit" id="submit" name="submit" />
</form>
Upvotes: 2
Reputation: 1651
I think that I see solution. You are sending data by POST method, but expect that they be in $_GET variable. Change one of methods (POST/GET) to another in Your code.
Upvotes: 3
Reputation: 276
You can add it to a hidden input like this:
<input type=hidden name=login_hint value="<?php echo $_GET['email'] ?>" >
Upvotes: 2