0

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

7
  • I do not see a problem in the code , have you tried and found any error? Commented Oct 19, 2013 at 13:55
  • 1
    what does this mean pass variable from input field? Commented Oct 19, 2013 at 13:55
  • It should work fine by using regular post code. Also you are missing an end-quote after the id tag. What is it you have tried, and what is your actual problem with the usual approach? Commented Oct 19, 2013 at 13:58
  • when i run this code... email field on login page of google is empty but when i write manual email on login_hint = [email protected] it appears on login page of google...if u know what i mean Commented Oct 19, 2013 at 13:58
  • Is your intentions to have the email that is typed into the email field to be added to the address, then JavaScript is a lot easier for this. Just have a click event that leads you to the link with the email appended at the end dynamically. Not sure if this is exactly what you desire to do, though. Commented Oct 19, 2013 at 14:02

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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>

Comments

2

You can add it to a hidden input like this:

  <input type=hidden name=login_hint value="<?php echo $_GET['email'] ?>" >

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.