Share this page

# web_submit_form

Submits a form.

## C Language

    int web_submit_form( const char *StepName, <List of Attributes>, <List of Hidden Fields>, ITEMDATA, <List of Data Fields>, [ EXTRARES, <List of Resource Attributes>,] LAST );

Action Functions

## Java Language

    int object.submit_form( String stepName, String[] options, String[] data );

Action Functions | Java Syntax

Argument | Description
--- | ---
object | An expression evaluating to an object of type WebApi. Usually web for Java. See also Function and Constant Prefixes.
StepName | The name of the form, as it appears in the graphical script. Also used as the transaction name for automatic transactions.
List of Attributes | See below in this section: List of Attributes.
List of Hidden Fields | See below in this section: List of Hidden Fields.
ITEMDATA | A marker that separates between the attributes and the data of the form. This marker is not used in Java Language calls.
List of Data Fields | See below in this section: List of Data Fields.
EXTRARES | A demarcation parameter indicating that the next parameter will be a list of resource attributes.
List of Resource Attributes | See List of Resource Attributes In Java language calls to lrapi.web.submit_form the list of extra resources is part of the data[] array.
LAST | A marker that indicates the end of the field list.

## Return Values

This function returns a 0 for success and a number greater than zero for failure.

## Parameterization

The following argument(s) can be parameterized using standard parameterization: List of Attributes, List of Hidden Fields, List of Data Fields

## General Information

The web_submit_form function is an action function that submits a form. (Each Web Action Function in a script causes the browser to display a new web page or frame. All Web Action functions can be recorded by VuGen.) The web_submit_form function may be executed only in the context of a previous operation.

web_submit_form is recorded only when VuGen is in HTML–based recording mode (see VuGen's Recording Options).

Examples of non–HTML–generated resources are .gif and .jpg images. The List of Resource Attributes is only inserted when the recording option for these resources is set at "Record within the current script step". This is the default setting. See the Virtual User Generator Help Center.

When web_submit_form is recorded, "name" and "value" are generally recorded for items in the ITEMDATA section. If you do not wish the recorded value to appear in the script, you can encode it. Change the word "Value" to "EncryptedValue", and substitute the encoded value for the recorded value. For example:

Change:

"Name=grpType", "Value=radRoundtrip", ENDITEM,

to:

"Name=grpType", "EncryptedValue=409e41ebf102f3036b0549c799be3609", ENDITEM,

To get an encoded value for later use, copy the value. Then go to Windows Start menu > Password Encoder. Paste the value into the Password field, and click Generate. The masked string appears in the Encoded String box. Click Copy and paste the masked string into a parameter for later use, or assign the value to a string variable.

Another option for encoding the value is to convert the entire value string to an lr_unmask call. Select an entire string between quote marks, not including the quote marks. Right-click in the string and select Mask String. The output looks like:

"Name=grpType", lr_unmask("40d176c46f3cf2f5fbfaa806bd1bcee65f0371858163"), ENDITEM,

This function is supported for all web scripts.

## List of Attributes

The following attributes are supported:

Action: The ACTION attribute of the FORM element. The ACTION attribute specifies the address (URL) to be used to carry out the action of the form. You can also specify Action/sfx, which indicates to search the form using the suffix of the action.

Frame: The name of the frame in which you recorded the operation. The name of the frame is the value of the name attribute of the FRAME element.

TargetFrame

ResourceByteLimit

UserAgent, and

Ordinal.

Recorded attributes: VuGen always tries to uniquely identify each form by recording only the data fields. If this is insufficient for unique identification, VuGen records the Action attribute. (This is the Action attribute of the Form element. The Action attribute specifies the address (URL) to be used to carry out the action of the form. You can also specify Action/sfx, which indicates to search the form using the suffix of the action.) If this is still insufficient for unique identification, VuGen records the Ordinal attribute, and not the Action attribute.

In Java Language calls to lrapi.web.submit_form the attribute list is part of the options[] array.

## List of Hidden Fields

Serves as an attribute. You can identify a form by using the list of the hidden fields.

The list of hidden fields has the following format:

    STARTHIDDENS,
        "name=n1", "value=v1", ENDITEM,
        "name=n2", "value=v2", ENDITEM,
        "NAMEPFX=pre1_", "NAMESFX=_sfx1", "value=v3", ENDITEM,
        "NAMEPFX=pre2_", "NAMESFX=_sfx2", "value=v4", ENDITEM,
    ENDHIDDENS,

The hidden fields list is optional.

name: The name attribute within an INPUT element of the field. It is the name of the field as it appears on the web page.

NAMEPFX and NAMESFX are the prefix and suffix of the name attribute within an INPUT element of a field. They identify an INPUT element when the name is dynamic but has a fixed prefix and suffix. The name attribute is the name of the field as it appears on the web page.

In Java Language calls to lrapi.web.submit_form the list of hidden fields is part of the options[] array.

## List of Data Fields

Data items identify a form. A form is identified by both data items and attributes.

The list of data fields has the following format:

"name=n1", "value=v1", ENDITEM,

"name=n2", "value=v2", ENDITEM,

name: The name attribute within an INPUT element of the field. It is the name of the field as it appears on the Wweb page.

In Java language calls to lrapi.web.submit_form the list of data fields is part of the data[] array.

## Changing the Header

The HTTP header can be modified to pass additional information about the request to the server. Using HTTP headers you can, for example, allow other content types in the response such as compressed files, or you can request a web page only on certain conditions. To modify the HTTP header in the request see web_add_header. To modify all subsequent requests, see web_add_auto_header.

## C Example

## Example 1

In the following example, the name of the web_submit_form function is "employee.exe". The function submits a request for information about the employee John Green. The function has no attributes because the form is uniquely identified by the item data.

    web_submit_form("employee.exe",
        ITEMDATA,
        "name=persons", "value=John Green - John", ENDITEM,
        "name=go_page", "value=Go to Page", ENDITEM,
        LAST );

## Example 2

In the following example, a user submitted a search in a company's library, for the book "Practical UNIX Security" by Garfinkel.

    web_url("dogbert", "URL=http://dogbert/", LAST );
    web_link("Departments:", "Text=Departments:", LAST );
    web_url("index.html", "URL=http://dogbert/groups/library/index.html", LAST );
    web_link("Book Search:", "Text= Book Search:", LAST );
    web_submit_form("db2net.exe",
        ITEMDATA,
        "name=library.TITLE", "value=Practical UNIX Security", ENDITEM,
        "name=library.AUTHOR_S_", "value=Garfinkel", ENDITEM,
        "name=library.SUBJECTS", "value=", ENDITEM,
        LAST );

## Java Example

In the following example, web.submit_form logs in to the WebTours application.

    try
    {
    web.url("WebTours",
        "URL=http://localhost/WebTours/",
        new String[]{
            "Resource=0",
            "RecContentType=text/html",
            "Referer=",
            "Snapshot=t1.inf",
            "Mode=HTML",
            web.LAST
        });

    web.url("home.html",
        "URL=http://localhost/WebTours/home.html",
        new String[]{
            "Resource=0",
            "RecContentType=text/html",
            "Referer=http://localhost/WebTours/welcome.pl?signOff=true",
            "Snapshot=t2.inf",
            "Mode=HTML",
            web.LAST
        });

    web.url("nav.pl",
        "URL=http://localhost/WebTours/nav.pl?in=home",
        new String[]{
            "Resource=0",
            "RecContentType=text/html",
            "Referer=http://localhost/WebTours/welcome.pl?signOff=true",
            "Snapshot=t3.inf",
            "Mode=HTML",
            web.LAST
        });

/* Notes on web.submit_form:
The options[] array must be present even if there are no options. Pass an empty new String function block as shown below.
The "data[]" string does not have a leading "ITEMDATA" delimiter as it would in the C language syntax.
Though the delimiters ENDITEM and LAST are lrapi.web constants, EXTRARES is not. EXTRARES is passed as a quoted string.*/

    //submit_form(String stepName, String options[], String data[])
    web.submit_form("login.pl", // stepName
        new String[]{}, // options[]
        new String[]{ //data[]
            "Name=username", "Value=jojo", web.ENDITEM,
            "Name=password", "Value=bean", web.ENDITEM,
            "Name=signup.x", "Value=59", web.ENDITEM,
            "Name=signup.y", "Value=13", web.ENDITEM,
            "EXTRARES",
            "Url=images/flights.gif",
        "Referer=http://localhost/WebTours/nav.pl?page=menu&in=home",
            web.ENDITEM,
            web.LAST
        });

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: