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?
For sending data to two servelets make one button as a submit and the other as button. On first button send action in your form tag as normal, but on the other button call a JavaScript function here you have to submit a form with same field but to different servelets then write another form tag after first close.
PHP - A Simple HTML Form When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.
You can't pass data directly html to php. You have to call ajax get/post request from html to php. then php return calculated data to your ajax success method. after you can print your calculated data inside html.
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 "[email protected]" .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With