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):

URLurl=newURL("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

URLurl=newURL("http://mywebsite/form-submit-webpage.php");
URLConnectionconn= url.openConnection();
conn.setDoOutput(true);
OutputStreamos= 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><formaction="welcome.php"method="post">
Name: <inputtype="text"name="name"><br>
E-mail: <inputtype="text"name="email"><br><inputtype="submit"></form></body></html>

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

<html><body>

    Welcome <?phpecho$_POST["name"]; ?><br>
    Your email address is: <?phpecho$_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"