Documentation
FormSaver 1.7 is now JavaScript Savvy!
With the aid of JavaScript, you can now provide conditional responses!
In other words, the user's response can be customized based on his form entries!
Use JavaScript in your forms!
Use JavaScript to make sure users fill out their forms correctly. Just
put standard JavaScript int the form's HTML file. Use this in conjunction
with FormSaver's "required" field, in case the user doesn't have JavaScript.
Be sure to use the new "SAVEJ" command instead of the "SAVE" command:
<INPUT TYPE="hidden" NAME="command" VALUE="SAVEJ">
Use JavaScript in your response files!
Here's where it gets exciting.
If you use the SAVEJ command in your HTML form, your FSR file will have access
to JavaScript variables that contain the form data, as entered by the user.
For example, if the user entered "Bob" for field1, "bob@domain.com" for
field2, and "Macintosh" for field3, FormSaver will put the following code
at the top of the response:
<SCRIPT>
<!--
var field1 = "Bob";
var field2 = "bob@domain.com";
var field3 = "Macintosh";
//-->
</SCRIPT>
Now, in your form's .fsr file, simply enter JavaScript code that uses these
variables! Here's an example .fsr file:
<SCRIPT>
<!--
document.write("<B>Name: </B>" + field1 + "<BR>");
document.write("<B>E-mail: </B>" + field2 + "<BR>");
document.write("<B>Conditional Message: </B>");
if (field3 == "Macintosh")
document.write("You chose the Macintosh! Apple would be proud!");
else if (field3 == "Windows")
document.write("You chose Windows! All hail Microsoft!");
else if (field3 == "UNIX")
document.write("You chose UNIX! Death to GUI!");
else
document.write("Error. Unexpected value: " + field3);
// -->
</SCRIPT>
So here's what the user will see!
Name: Bob
E-mail: bob@domain.com
Conditional Message: You chose the Macintosh! Apple would be proud!
Important Note #1
Variables will only be created for fields that FormSaver knows about. For
example, if the user fills in fields 1 and 3, but leaves 2 and 4 blank, FormSaver
will create variables for 1, 2, and 3. It had no idea that 4 was supposed to exist.
It will create an empty variable for field2. If you try to access a variable that
does not exist, JavaScript will report an error. Example:
<SCRIPT>
<!--
var field1 = "Bob";
var field2 = "";
var field3 = "Macintosh";
//-->
</SCRIPT>
So if you try to use a "field4" variable, JavaScript will give an error on the user's browser.
Solution #1: Use FormSaver's "required" tag to designate fields as required, if you
plan on using them in the response file. Also, use JavaScript in the form itself,
to make sure users enter data for those fields. This is not a good solution for checkboxes,
because there is no value when it is not checked.
Solution #2: Make the largest numbered variable required. If FormSaver knows about field5,
it will automatically created fields 1-4 as well.
Solution #3: Use FormSaver's numfields tag. This tells FormSaver how many fields are
meant to be in the form. It is important to update this field if you add more fields, or
else FormSaver will report an error. Here's how to tell FormSaver there are 4 fields:
<INPUT TYPE="hidden" NAME="numfields" VALUE="4">
Important Note #2
JavaScript is case-sensitive. Variables will be called "field#" (all lowercase), regardless of how they are named in your form!
Pliner Solutions is located in Willow Grove, near Philadelphia, Pennsylvania, although we have have clients worldwide.
Please contact us for more information about Pliner Solutions FormSaver product questions, or if you have problems using FormSaver at (215) 658-1601 or use our convenient online form.