Changed Action URLs on Form Submission

JavaScript can be used to change the action URL of a form.

function SubmitSearch(linkUrl)
{
  document.searchForm.action = linkUrl;
  document.searchForm.submit();
}
...
<form name="searchForm"
      method="POST"
      target=_self>
  <input type=input name="searchString" value="">
  <input type=hidden name="BV_SessionID"
                     value="@@@@1245417051.1003814911@@@@">
</form>
<a href="JavaScript:SubmitSearch('http://my.server.com/search.asp')">
   Search this site</a>
<a href="JavaScript:SubmitSearch('http://my.mirror.com/search.asp')">
   Search mirror site</a>

Specifying a different absolute action URL

Assume that this page was downloaded by the function call

WebPageLink("Advanced Search");

Using the Silk Performer context-full WebPageSubmit function is a better choice because it automatically handles the hidden field BV_SessionID without having its value in the script.

To facilitate this, Silk Performer has the option of specifying a different action URL to use with the WebPageSubmit function.

The function used to do this is WebPageSetActionUrlAbs. If this function is called before a call to WebPageSubmit, the URL specified in the WebPageSetActionUrlAbs function is used rather than the action URL specified in the HTML code.

Using this function, the BDL code above would be rewritten as:

WebPageLink("Advanced Search");
WebPageSetActionUrlAbs("http://my.mirror.com/search.asp");
WebPageSubmit("searchForm", FORM_SEARCH);
...
dclform
  FORM_SEARCH:
    "searchString"   := "discount",
    "BV_SessionID"   := "" <USE_HTML_VAL>;
Note: The use of WebPageSetActionUrlAbs allows you to use the context-full WebPageSubmit function rather than the context-less WebPageForm function, and so allows you to use the FORM_SEARCH form in a context-full way.

The Silk Performer recorder automatically generates the WebPageSetActionUrlAbs function when it allows for generation of the function WebPageSubmit rather than a context-less function.

To enable this feature, select the Allow modified action URLs checkbox on the Advanced Context Management Settings dialog box at Settings > Active Profile > Web > Recording tab.

Specifying a different parsed action URL

While specifying a different absolute action URL offers an advantage in that it allows for the use of a context-full form, the URL is still context-less and hard coded into the script.

If the action URL also contains state information, the action URL needs to be specified context-fully.

This can be done using the WebPageSetActionUrl function. Unlike the WebPageSetActionUrlAbs function, the WebPageSetActionUrl function receives the name of a parsed URL rather than an absolute URL.

It is possible to parse custom URLs for use with the WebPageSetActionUrl function. To demonstrate, the example above can be rewritten as follows:

WebPageParseUrl("Form Action", "SubmitSearch('", "'");
WebPageLink("Advanced Search");
WebPageSetActionUrl("Form Action", 2);
WebPageSubmit("searchForm", FORM_SEARCH);
...
dclform
  FORM_SEARCH:
    "searchString"   := "discount",
    "BV_SessionID"   := "" <USE_HTML_VAL>;

This example uses the second occurrence of the parsed URL Form Action to set the action URL to http://my.mirror.com/search.asp. The script can handle state information that may be contained in the action URL.

The Silk Performer recorder can automatically generate calls to the WebPageSetActionUrl function and the corresponding call to WebPageParseUrl, rather than calling WebPageSetActionUrlAbs.

To enable this feature, select the Dynamic action URL parsing checkbox on the Advanced Context Management Settings dialog box at Settings > Active Profile > Web > Recording tab.