As you might guess, getting the value for the form’s action attribute, as well as the field names, is pretty straightforward. First, here is the definition for the “getFormAction()” function, which not surprisingly obtains the form action’s value:
// function getFormAction
var formaction=document.getElementsByTagName('form') .getAttribute('action');
As you can see, the function simply uses the methods provided by the DOM to obtain the URL specified as the form’s action attribute, and returns its value. Here, the scripts makes a rough assumption, by considering that the requested page contains only one form. Anyway, if more forms are coded within the same page, it’s fairly easy to adapt the code for dealing with multiple forms.
Once the program has obtained the URL where the form values will be processed, it needs to get the names of the corresponding fields, which will be populated with random strings. So, here is the list for the “getFormVariables()” function:
// function getFormVariables
var childElements=document.getElementsByTagName('form') .childNodes;
// check if field name contains the string 'email' formvars+=(/mail/.test(childElements [i].getAttribute('name')))?childElements [i].getAttribute('name')+'='+getRandomEmail() +'&':childElements[i].getAttribute('name') +'='+getRandomValue()+'&';
Basically, what the above function does is obtain the names that correspond to the form fields. As they’re obtained trough a regular loop, they’re populated with random data. Notice that the function roughly attempts to find out if the field’s name contains the string “mail”. In this case, the form variable will be populated with a pseudo randomly-generated email address, which is obtained by calling the “getRandomEmail()” function.
The expression listed above uses either the “getRandomEmail()” function, in the case of having a field that suggests entering an email address, or “getRandomValue()”, for populating other fields. Lastly, the function returns a string in the form of name=value pairs that will be sent as form data.
As I said previously, don’t feel concerned about how those undefined functions look, since they will be reviewed over the next few lines. All you have to do is keep on reading.