Handling Dynamic Form Actions

The action property of an HTML form controls what the web browser will do if the user presses the form's submit button. For most forms, the action property is set to a static page. In ASL scripts this is easily handled by just hardcoding the interaction, something like this:

http get,redir "/search.asp"
form searchPhrase="web site monitoring"
http post,redir,encode "/dosearch.asp"

Each time it is run, this script will first get the search page where the search form is located. Assuming that works OK, the script will then do what the form would have done: activate the searching function to find the phrase, "web site monitoring." But what to do if the search form does not use a static action? Maybe the website wants to assign a unique ID to each search and the way it does that is by passing parameters to the URL specified in the action. Something like this:

<form name="frmSearch" action="/dosearch.asp?id=680813">
...

For these situations you can use the ASL scripting command 'parseform' that allows you to retrieve attributes of the form and the objects it contains. We can use parseform to resolve the problem above:

http get,redir "/search.asp"

parseform "frmSearch"

form searchPhrase="web site monitoring"
http post,redir,encode $FROM_frmSearch_ACTION

When calling the 'parseform' command, you must supply the name of the form. If your form does not have a name, the default name is "alertraMAIN," which you can use to refer to the unnamed form.

Accessing Input Elements

You can also use 'parseform' to access the values of input elements. In fact, a side-effect of calling 'parseform' is that it copies all hidden input elements automatically to the form you are building with 'form' statements. For instance, if your server runs .NET then your forms will have hidden __VIEWSTATE input elements on them. By calling 'parseform' the __VIEWSTATE element will be copied to a form variable and will be automatically submitted when you call 'http post'.

'parseform' puts the values of other form input elements into variables you can access. For instance, lets assume a form that has an input element "custid" that you want access to in your script. The following code would do the trick:

http get,redir "/custinfo.php"

parseform "frmCustomer"

info $INPUT_frmCustomer_custid_value