Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
The HTML Form Element represents a section containing input controls for submitting user information. Using our library, you can easily fulfill the HTML forms and send data directly from your C# application. To make this process much more comfortable, we designed the Aspose.Html.Forms namespace. The main element of this namespace is FormEditor. It allows you to find an existing form in the document, create a new one from scratch, iterate through the elements, fill them up with data, and surely send the information to the remote server.
In this article, you will learn how to work with a FormEditor object to manipulate HTML form in the document, input controls, and submit information. For the testing purpose, we use the form designed by https://httpbin.org service.
Let’s look at the C# code snippet that demonstrates how to use the Aspose.Html.Forms namespace to programmatically fill and submit an HTML form. You need to follow the next steps:
editor object. 1// How to to programmatically fill and submit an HTML form in C#
2
3// Initialize an instance of HTML document
4using (HTMLDocument document = new HTMLDocument(Path.Combine(DataDir, "form.html")))
5{
6 // Create an instance of Form Editor
7 using (FormEditor editor = Aspose.Html.Forms.FormEditor.Create(document, 0))
8 {
9 // You can fill the data up using direct access to the input elements, like this:
10 editor["custname"].Value = "John Doe";
11
12 document.Save("out.html");
13
14 // or this:
15 TextAreaElement comments = editor.GetElement<Aspose.Html.Forms.TextAreaElement>("comments");
16 comments.Value = "MORE CHEESE PLEASE!";
17
18 // or even by performing a bulk operation, like this one:
19 editor.Fill(new Dictionary<string, string>()
20 {
21 {"custemail", "john.doe@gmail.com"},
22 {"custtel", "+1202-555-0290"}
23 });
24
25 // Create an instance of form submitter
26 using (FormSubmitter submitter = new Aspose.Html.Forms.FormSubmitter(editor))
27 {
28 // Submit the form data to the remote server
29 // If you need you can specify user-credentials and timeout for the request, etc.
30 SubmissionResult result = submitter.Submit();
31
32 // Check the status of the result object
33 if (result.IsSuccess)
34 {
35 // Check whether the result is in json format
36 if (result.ResponseMessage.Headers.ContentType.MediaType == "application/json")
37 {
38 // Dump result data to the console
39 Console.WriteLine(result.Content.ReadAsString());
40 }
41 else
42 {
43 // Load the result data as an HTML document
44 using (Document resultDocument = result.LoadDocument())
45 {
46 // Inspect HTML document here.
47 }
48 }
49 }
50 }
51 }
52}Aspose.HTML offers HTML Web Applications that are an online collection of free converters, mergers, SEO tools, HTML code generators, URL tools, and more. The applications work on any operating system with a web browser and do not require any additional software installation. Easily convert, merge, encode, generate HTML code, extract data from the web, or analyze web pages in terms of SEO wherever you are. Use our collection of HTML Web Applications to perform your daily matters and make your workflow seamless!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.