Kevin Kevin - 2 months ago 6
HTML Question

Getting value of HTML text input

Say I have an HTML form like this to collect an email from a website visitor:

<form name="input" action="handle_email.php" method="post">
Email: <input type="text" name="email" />
<input type="submit" value="Newsletter" />

Now when the submit button is pressed I can get the value of the email field in handle_email.php by using $_POST["email"]. But say I'd like to use the value of the email text input elsewhere. Is it possible to get the email value "outside" of the form processing?

UPDATE: Thanks to everyone for their quick replies. What I'm trying to do is get the email box to do double-duty. For example, I've renamed the submit button to "Newsletter" in the above code. When that button is pressed the handle_email.php script will just sign up the user for a newsletter. However, I also have a "Register" link on the same page that redirects the visitor to a registration form where they can enter lots of other info if they like. Now, if the user happened to have entered data in the email text box I'd like to send it along to the registration page so that field can be pre-populated. For example:

<a href=""[how can I put the email here?]"/>Register</a>

My apologies for not being clear enough in my original post.



See my jsFiddle here:

Whenever you change the email field, the link is updated automatically. This requires a small amount of jQuery. So now your form will work as needed, but your link will be updated dynamically so that when someone clicks on it, it contains what they entered in the email field. You should validate the input on the receiving page.