11

I have a form on my homepage and when it is submitted, it takes users to another page on my site. I want to pass the form data entered to the next page, with something like:

<?php echo $email; ?>

Where $email is the email address the user entered into the form. How exactly do I accomplish this?

2

1 Answer 1

34

The best way to accomplish that is to use POST which is a method of Hypertext Transfer Protocol https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

index.php

<html>
<body>

<form action="site2.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">
</form>

</body>
</html> 

site2.php

 <html>
 <body>

 Hello <?php echo $_POST["name"]; ?>!<br>
 Your mail is <?php echo $_POST["mail"]; ?>.

 </body>
 </html> 

output

Hello "name" !

Your email is "whatyou@addedonindex.com" .

6
  • I am posting the data into html code on the page, not plain text like that, does it matter? (I have an iframe on site2.php and I am passing the info to the iframe URL). Mar 6, 2013 at 0:30
  • No, doesn't matter, where you POST it. It can be text, table, button, paragraph etc...
    – Stepo
    Mar 6, 2013 at 0:31
  • if i want to load site2.php content in dialog box then how can i do that. i refered this
    – Dimple
    May 20, 2015 at 8:28
  • @Stepo there are any other way available for transfer data ? Aug 29, 2016 at 9:55
  • This is what I wanted to find. Thank you. This works !
    – Pokemon
    Jun 21, 2018 at 8:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.