Thread Rating:
  • 627 Vote(s) - 2.68 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forms3:HTTP Forms
06-15-2011, 05:02 PM, (This post was last modified: 06-16-2011, 10:46 AM by kino.)
Forms3:HTTP Forms
One of the most common ways to communicate with a server is over HTTP. Curl's HttForm class acts as a container for controls that will be part of the web form. Users complete the form by modifying its controls before submitting hte form to an agent for processing. The function of HttpForm is similar to the FORM tag in HTML.

Lets look at the following simple example. In this case, we are creating a Google query that also specifies the language and the interface. Enter text that you would like to query in Google, e.g. "Baseball". Then hit thie "Submit" button. A new browser window will be launched to display the results.

width='100%' height='60' src='../../wiki/samples/Forms/http2.curl'

In this case, HttpForm is used to create the Web form

•A Dialog is created to contain the controls

•The user fills out the form and clicks the Submit button

•Key/value pairs are sent to the server script using GET or POST

•Returned information is sent to the user

When instantiating an HttpForm object, you provide the URL of the CGI program or script on the Web site that will receive the request, as well as the HTTP request method of GET or POST.

Let's break down this example. First we will create an form that only submits the query. Afterwards, we can add the additional query elements and expand the example.

width='100%' height='450' src='/wiki/samples/generic-example.curl?Forms/http.curl'

In this example, we will be sending the following HTTP request using GET: (where "Baseball" represents the text typed in by the user). In order to accomplish this, we need to first specify the url of the server.

The target specifies the browser window in which the action will be displayed. Values are as follows:

•_self: Returns results in the current browser window (default)

•_blank: Returns results in a new browser window

•_parent: Returns results in the parent frameset of the current frame.

•_top: Returns the results in the top-level window (full browser window)

Since the HttpForm is a Dialog, we must create one child object that can contain multiple children. In our example, we are using a VBox. Control values that are passed to the HTTP request must include the name attribute. The TextField has name = "q" defined.

    width = 2in,
    name = q

The submit-button is a Curl procedure that creates a CommandBuitton with at "Submit" label. When the user clicks on the button, it automatically passes the form information to the specified Url.


We have created this proc as a convenience procedure. For custom submit functionality, you can always create your own procedure or method. Another convenience procedure that we have created for you is reset-button. In this case, it creates and returns a standard "Reset" button for use in the HttpForm. Let's add this functionality to our example.
{curl 6.0, 7.0 applet}
{curl-file-attributes character-encoding = "utf8"}
{applet manifest = "manifest.mcurl",
   {compiler-directives careful? = true}

   {url ""},
   target = "_blank",
       margin = 5pt,
       spacing = 3.5pt,
       {text Query:  },
           width = 2in,
           name = "q",
           value = "Pizza"

Note that the reset button will 'reset' all controls to their default state. In the above example the initial value has been set to "Pizza". If no initial value is specified, the "Reset" button will leave the TextField blank.

Messages In This Thread
Forms3:HTTP Forms - by kino - 06-15-2011, 05:02 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Persistent Data2:HTTP Cookies kino 0 6,502 06-15-2011, 05:27 PM
Last Post: kino
  Forms1:Creating Forms kino 0 5,336 06-15-2011, 04:55 PM
Last Post: kino
  Files over HTTP1:Files over HTTP kino 0 4,689 06-15-2011, 04:30 PM
Last Post: kino
Forum Jump:

Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
INSERT INTO mybb_threadviews (tid) VALUES('22')