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
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>
You can add it to a hidden input like this:
<input type=hidden name=login_hint value="<?php echo $_GET['email'] ?>" >
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.