Skip to content Skip to sidebar Skip to footer

Fill A PHP/HTML Field In A Website

I want to automatically fill the field called 'email' of a webpage thesite.com/email.php, which code is something similar to this:

Solution 1:

To programmatically submit the form with java, you don't directly fill the form, rather send the form information to the submit page via HTTP GET or POST. You did not provide the onsubmit value in your post, but you would use that webpage URL and send the form information via a URLConnection. If using GET, you send the data in a query string (where key/value are the form parameters):

URL url = new URL("http://mywebsite/form-submit-webpage.php?key1=value1&key2=value2");

If POST, you must use the OutputStream of URL connection to set the POST key/value pairs

URL url = new URL("http://mywebsite/form-submit-webpage.php");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
//write key value pairs to os. 

From their, get get the InputStream from the URLConnection to read the results. See https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html


Solution 2:

What you need to do is create a form in html and a form handler in php.

HTML code posting the information to "welcome.php"

<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

welcome.php can handle the variables in different ways. Here is an example:

<html>
<body>

    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

The file will pass the variables by their names. In this example, the names are "name" and "email" using the post method. In the php file, you receive the variables useing the $_POST method.


Post a Comment for "Fill A PHP/HTML Field In A Website"