web design and hosting
features and pricing my account customer support about ICG Link, Inc. contact ICG Link, Inc.

Form.pl: Advanced Features
Our form script is a powerful, yet easy-to-use tool that will make your web site more interactive and useful for your visitors. The script allows you to create a web page with fields that are filled out by a visitor and then perform various tasks with that information. When the form is submitted, the information can be sent by email to a recipient or recipients in any format you choose, it can be saved to a file in any format you choose and the script can send the visitor to a plain results page or one that presents the data as submitted or presents altered information based on any calculations or automatic decisions you may want to apply to the information. When used in combination with the search and replace scripts, you can even use this script to enter content you manage from a back office administration area.

Select the article that describes the form script functions you need.
  • The Basics: Send and format an email message, write to a file in a format of your choice, specify required fields, set up an error page.
  • Advanced Form Functions (this article): Set and check cookies, perform calculations with built in math functions, manipulate text, use if - then logic, use a wide variety of preset values and more.
  • Upload Files: upload one or several files with a single submission, resize image files on the fly, create image thumbnails at the same time and more.
  • Send Encrypted Mail: Send encrypted email messages with GnuPG.
  • Perform Secure Transactions & ecommerce: Use the form script on our secure server and enjoy useful features dedicated to e-commerce.

The variable f_htmlblock can be added to avoid spammers from using your form to send links to their web sites in certain fields. The value for this variable is a comma-separated list of fields in your form that will cause form execution to be blocked if they contain links in the form <a href= or [URL=.

    To store a field as a cookie, name it c_fieldname. f_expires sets the expiration date in days. To check for cookies and send user where they need to go: <INPUT TYPE="hidden" name="x_success" value="($c_cookiename) ? blah...">

Create a hidden field on your form with a name that starts with "x_". Set the VALUE to the calculation you would like to process.
    <INPUT TYPE="hidden" NAME="x_somename" VALUE="5 + 6">

    Parenthesis are helpful for more complex calculations.
Fields: The other fields in your form can be used as variables in the calculation. Include any field by placing a "$", dollar sign, in front of the field name. For example, say you are selling Big K Cola for $.25 and Dr. Pepper for $.50. Your form would ask for how many of each item the user would like to buy. Here is the HTML for the page.
    <INPUT TYPE="text" NAME="bigkcola" SIZE=5> Big K Cola<BR> <INPUT TYPE="text" NAME="drpepper" SIZE=5> Dr. Pepper<BR> <INPUT TYPE="hidden" NAME="x_subtotal" VALUE="($bigkcola * .25) + ($drpepper * .50)">
If the user wanted to buy 3 Big K Colas and 6 Dr. Peppers, after the user clicks the submit button, the value of field "x_subtotal" will equal 3.75. A mail template file might look like this:
 <! FIELD="bigkcola"> Big K Cola @ $.25
 <! FIELD="drpepper"> Dr. Pepper @ $.50
 Subtotal $ <! FIELD="x_subtotal">
and would return mail looking like this:
 3 Big K Cola @ $.25
 6 Dr. Pepper @ $.50
 Subtotal $ 3.75

+ :Addition (plus)
- :Subtraction (dash)
* :Multiplication (asterisk)
/ :Division (slash)
% :Modulo (percent) Modulo is used just like division, except it returns the remainder. For example, 10 / 3 = 3 with a remainder of 1, 10 % 3 = 1
atan2(x,y) :arctangent
sin(x) :sine of x measured in radians.
cos(x) :cosine of x measured in radians.
dollar(x) :rounds x to two decimal places. For example, if you calculate a total of 25.75 in $x_subtotal and want to multiply by a tax of 8.25%, the calculation $x_subtotal * .0825 would return 2.124375. By using dollar($x_subtotal * .0825), you would receive the result 2.12, instead.
round0(x) :rounds x to the nearest whole number, e.g., round0(3.5468923) will return 4.
round1(x) :rounds x to 1 decimal place, e.g., round1(3.5468923) will return 3.5, and round1(3) will return 3.0.
round2(x) :rounds x to 2 decimal places, e.g., round2(3.5468923) will return 3.55, and round2(3) will return 3.00.
round3(x) :rounds x to 3 decimal places, e.g., round3(3.5468923) will return 3.547, and round3(3) will return 3.000.
round4(x) :rounds x to 4 decimal places, e.g., round4(3.5468923) will return 3.5469, and round4(3) will return 3.0000.
exp(x) :e to the power of x.
hex(x) :decimal value of a hexadecimal number. For example, hex('ff') will return 255.
int(x) :integer value of x. For example, int(3.1315) will return 3.
log(x) :logarithm (base e) of x.
oct(x) :decimal value of an octal number. For example, oct('77') will return 63.
ord(x) :numeric ASCII value of x. For example, ord('A') will return 65. Only the first letter is processed, so ord('Aardvark') will also return 65.
rand(x) :random fractional number between 0 and x. For example, rand(5) might return 4.39422607421875. This function is most useful when used with the int() function. To simulate one dice, int(rnd(6))+1. The rand() function will return a fractional number from 0 to 5.99999... The int() function makes the result 0 to 5 and the 1 is added to make the result an integer between 1 and 6.
sqrt(x) :square root of x.


To use text within a calculation, enclose it in single quotes ('').

. (period) concatenates two text strings together. Think of it as addition for text. For example, to piece together someone's last name and first name with a comma and a space, use $lastname . ', ' . $firstname

  • length(a) returns the number of characters in variable a.
  • rindex(x,y) returns something I can't remember.
  • substr(x,y,a) substring of variable a that starts at character number x and is y characters long.

DYNAMIC PARAMETERS - Control who receives e-mail or where the next page takes you by defining the form settings with calculations.

(if) ? then : else


To test to see whether a first condition AND a second condition are fulfilled.

<input type=hidden name="x_success" value="(($radio == 1) && ($list == 1)) ? 'http://www.wherever.com/a2.html' : (($radio == 2) && ($list == 1)) ? 'http://www.wherever.com/a3.html' : (($radio == 1) && ($list == 2)) ? 'http://www.wherever.com/a3.html' : (($radio == 2) && ($list == 2)) ? 'http://www.wherever.com/a4.html' : 'http://www.wherever.com/fail_needmore.html'">

Notes: the innermost parentheses are optional, used here to better visually order the items being tested; 'eq' can also be used in place of ' == ' without effecting the result.

  • <input type="hidden" name="x_success" value="($category =~ /brass/) ? '/project/step3a.html' : '/project/step3b.html'"> sends the visitor to step3a if brass is the category, otherwise step3b is used.
  • <input type="hidden" name="x_data" value="(-e $x_path) ? '' : $r_pin.'.data'"> Let's say the required field r_pin is given the value "1234". This statement says that if $x_path exists, x_data is blank, otherwise, the data file will be called 1234.data.
  • <input type="hidden" name="x_price" value="($size eq '1x3') ? '0' : '<! field="pcs1">'"> This statement says that if $size is 1x3 then set x_price to 0, otherwise set it to the value of pcs1 from a previous page.
  • <input type="hidden" name="x_value" value="($r_quantity lt 5) ? '<! field="pc1">' : ($r_quantity lt 10) ? '<! field="pc5">' : ($r_quantity lt 25) ? '<! field="pc10">' : ($r_quantity lt 50) ? '<! field="pc25">' : ($r_quantity lt 100) ? '<! field="pc50">' : ($r_quantity lt 250) ? '<! field="pc100">' : ($r_quantity lt 500) ? '<! field="pc250">' : ($r_quantity lt 1000) ? '<! field="pc500">' : ($r_quantity lt 2500) ? '<! field="pc1000">' : '<! field="pc2500">'"> sets x_value based on quantity.
  • <input type="hidden" name="x_success" value="(lc($r_password) eq 'blowmedown') ? 'http://www.pirates.com/gold.html' : 'http://www.pirates.com/plank.html'"> sets the success page based on correctly entering a password ignoring case.
  • <input type="hidden" name="x_tax" value="($r_State eq 'TN') | ($ShippingState eq 'TN') ? dollar($x_taxamt * .0825) : 0 "> This uses an "or" (the |) function.
  • <input type="hidden" name="x_complete" VALUE="($complete gt 0) ? '<LI>Complete 2-volume set - $' . $complete : ''"> If the value of $complete is greater than zero, set x_complete to a bullet and some text otherwise leave it blank.
  • <input type="hidden" name="x_next" value="($size == '12') ? 3 : ($size == '745') ? 2 : 1"> If size is 12, x_next is 3 or if size is 745, x_next is 2 otherwise it's 1.
  • <input type="hidden" name="code" value="^d{7,8}$">
    <input type="hidden" name="x_success" value="($entry =~ /$code/) ? 'http://www.foo.com/index.html' : 'http://www.foo.com/fail.html'"> To allow any seven or 8 digit numbers - (w will allow letters and numbers)
  • v_year - a number for the year.
  • v_mon - a number 1 - 12 for the month.
  • v_monshort - the abbreviated name of the month. ie: "Sep"
  • v_monlong - the full name of the month. ie: "September"
  • v_yday - a number 1 - 366 for the day of the year.
  • v_mday - a number 1 - 31 for the day of the month.
  • v_wday - a number 1 - 7 for the day of the week.
  • v_dayshort - the abbreviated name of the day of the week. ie: "Thu"
  • v_daylong - the full name of the day of the week. ie: "Thursday"
  • v_hour - a number 0 - 23 for the hour of the day.
  • v_min - a number 0 - 59 for the minute.
  • v_sec - a number 0 - 59 for the second.
  • v_isdst - "1" if it is Daylight Savings Time "0" if not.

    For example:
  • <! FIELD NAME="v_daylong"> references the day of the week.
  • <INPUT NAME="x_date" VALUE="$v_mon . '/' . $v_mday . '/' . $v_year"> formats the date with numbers and slashes, like 9/3/98. The periods concatenate the date fields and the slashes.

  • v_unique - returns a unique number. (Technically, the number of seconds since 1/1/1970.)
  • v_computer - returns the OS the visitor is using: Unix, Windows 95, Windows NT, Windows 32bit, Windows 16bit, Macintosh, PowerMac, OS/2, Amiga, WebTV, Unknown
  • v_browser - returns the browser: America Online, Microsoft Internet Explorer, Netscape Navigator, IBM WebExplorer, QuarterDeck Mosaic, SPRY Mosaic Lynx, Cyberdog, NCSA Mosaic, IBrowse, NetCruiser, WebTV, Unknown
  • v_addr - returns the IP address. ie:
  • v_agent - returns the description line reported by the browser. It may contain the browser, version of the browser, computer and/or operating system.
  • v_referer - returns the URL of the previous web page.

    Allow Carriage Returns
  • f_cr - If you want to include formatted text in a variable (i.e. with carriage returns), you must disable a function of the script that removes these. This can be done by creating a hidden feild called f_cr with the value "yes".
(requires visitor to enter his name, sends mail to a different recipient and selects a different sender depending on the value of certain variables, writes to a file.)

<form method="POST" action="/cgi-bin/form.pl">
<input type="hidden" name="f_subject" value="New Project">
<input type="hidden" name="f_data" value="project.data">
<input type="hidden" name="f_format" value="/project.format.data">
<input type="hidden" name="f_template" value="/project.template.data">
<input type="hidden" name="f_success" value="/thanks.html">
<input type="hidden" name="f_required" value="http://www.foo.com/required.html">
<input type="hidden" name="f_error" value="error.html">
<input type="text" name="r_name">
<select name="Requester"> Who are you?
<option value="Contractor" selected>Contractor</option>
<option value="Architect">Architect</option>
<option value="Developer">Developer</option>
<option value="Tenant">Tenant</option>
<select name="ActionBy"> Who gets this?
<option value="Contractor" selected>Contractor</option>
<option value="Architect">Architect</option>
<option value="Developer">Developer</option>
<option value="Tenant">Tenant</option>
<input type="hidden" name="x_number" value="$v_unique">
<input type="hidden" name="x_sender" value="($Requester eq 'Contractor') ? 'contractor@foo.com' : ($Requester eq 'Architect') ? 'architect@foo.com' : ($Requester eq 'Developer') ? 'developer@foo.com' : 'tenant@foo.com'">
<input type="hidden" name="x_recipient" value="($ActionBy eq 'Contractor') ? 'general@foo.com,project@foo.com' : ($ActionBy eq 'Architect') ? 'architect@foo.com,project@foo.com' : ($ActionBy eq 'Developer') ? 'developer@foo.com,project@foo.com' : 'tenant@foo.com,project@foo.com'">
<input type="hidden" name="x_RequestDate" value="$v_mon.'/'.$v_mday.'/'.$v_year">
<input type="submit" value="Go">
ICG Link, Inc. 7003 Chadwick Drive, Suite 111, Brentwood, TN 37027