This section will allow your form to perform calculations which can then send your visitors to other web sites, update databases, print information back to the user, download files, or send e-mails.

There are several commands that tell $title_tag what to do when the result of an equation is true:

  1. GOTO Sends the visitor to another web site or $title_tag form
  2. PRINT displays text that you specify to the visitor
  3. PRINTEND displays text that you specify to the visitor and stops processing other calculations
  4. PRINTARRAY displays a list of values that are read in from a database
  5. SET will set a new variable to be used in your calculations
  6. DOWNLOAD begins a file download from your web site to the visitor
  7. EMAIL sends an e-mail message to someone
  8. READ loads a text file in memory from $title_tag's subfolders
  9. READDB loads an entire database in memory
  10. WRITE adds a new record to a specified database
  11. UPDATE changes an existing record in a database
Any element in your form can be used in a calculation, and the result of the calculation can also be used. All you need to do is surround your element name in exclamation points to tell $title_tag to use its value that the user filled into the form.

Let's say your form had elements named FirstName and LastName.

To use them in a calculation, they would be referenced as !FirstName! and !LastName!. So, if someone typed in John as their first name in your form, then !FirstName! would contain John.

All calculations begin with IF and must be surrounded in parenthesis (). However PRINT, PRINTEND, GOTO, SET, DOWNLOAD, EMAIL can be used on a line by themselves.

Examples:

IF ("!num1!" + "!num2!" == "10") GOTO "http://www.anothersite.com/10.html"
IF ("!num1!" - "!num2!" * "!num7!" > "100") GOTO "http://www.aWebSite.com/BigNumber"
IF ("!ChosenNumber!" == "1") PRINT "Thank you choosing one"
IF ("!ZipCode!" == "90210") PRINTEND "We are not accepting orders in Beverly Hills"

There several operators you can use to compare values in $title_tag:

== Tests if two or more numbers are equal
!= Tests if two or more numbers are not equal
+ Add numbers together
- Subtracts numbers
* Multiplies numbers
/ Divides numbers
EQ Tests if two or more text values are equal
NE Tests if two or more text values are not equal
=~ Tests if a value is like another. Does not have to be exact like == or EQ
!~ Tests if a value is not like another. Does not have to be exact like != or NE

Passing values to other pages

IF ("!myAge!" < "50") GOTO "http://www.website.com/YoungLiving!!myAge!!.html"

Let's say your visitor enters 35, then they will be sent to:
http://www.website.com/YoungLiving35.html

Or maybe you only want submissions from people over 18. You could do this:

IF ("!myAge!" < "18") PRINTEND You are only !myAge!. You must be 18.

Comparing Text

$title_tag uses two special operators to determine if you are comparing text. They are EQ (equal) and NE (not equal). Anything except numbers is considered text.

For example:

IF ("!Name!" EQ "John Smith") GOTO "http://www.johnsmithwebsite.com"

The above would require that all capitalization be exact. If you don't care about the case, do this:

IF ("\U!Name!\E" EQ "JOHN SMITH" GOTO "http://www.johnsmithwebsite.com"

This tells $title_tag the equation will match if the user enters JOHN SMITH or even john SMIth. All you need to do is start your element variable with \U and end it with \E and be sure the text is in all capital letters.

Comparing similar values with like and not like

If you want only a portion of the text to match, you can use either =~ (like) or != (not like). Both of these operators require a search pattern, so they are written a little differently.

Let's say you wanted anyone that had a portion of their name with John in it to be forwarded to CGI Connection.

Your calculation would look like this:

IF ("!FirstName!" =~ m/JOHN/ig) GOTO "http://www.cgiconnection.com"

The user could enter John, JoHn, JOHN, Johnny, John Smith, Smith John, and they would all result in a match.

The text you want to search for must be surrounded in m//. The ig portion tells $title_tag that capitalization does not matter.

Comparing multiple element values

You can use a couple different operators depending on what you're comparing. The operators available are && and ¦¦.

&& (AND) and ¦¦ (OR) are used for comparing two separate equations at one time.

For example:

IF ("!num1!" == "1" ¦¦ "!num2!" == "2") PRINT "You chose 1 or 2"

Here's another example:

IF ("!FirstName!" EQ "JOHN" && "!LastName!" NE "SMITH") PRINT "You are not John Smith"

Getting the result of a calculation

Sometimes you may want the result of a calculation and use that to tell the visitor something or send them to another place. There are two variables that hold this information. They are !FIRSTEQRESULT! and !SECONDEQRESULT!. These variables will not be available when comparing multiple values as shown above.

Let's say your calculation is this:

IF ("!num10!" - "!num9!" < "!num1!" + "!num2!") GOTO "http://www.yourwebsite.com/page!FIRSTEQRESULT!

The result of num10 - num9 is now in the variable !FIRSTEQRESULT! and the result of num1 + num2 is in !SECONDEQRESULT!. Basically $title_tag will split the calculation in two parts, and get the separate values of each.

In this example !FIRSTEQRESULT! will be replaced with the result of num10 - num9 and the visitor will be forwarded to that URL if the value is less than the result of num1 + num2.

Setting new variables

Sometimes you will want to set a new variable to be used later in your calculation. Here's an example:

IF ("!Name!" EQ "JOHN") SET "!FoundJohn! = 1"
IF ("!FoundJohn!" == "1") PRINTEND "Your name is John"

You can use set on a line by itself to define a variable outside of a calculation. For example:

SET "!NewNumber! = 15"

You will now have access to the variable, !NewNumber! to be used in any other calculation. Here's an example.

IF ("!NewNumber!" > "1") PRINTEND "NewNumber is greater than one"

You should make sure any new variables that you set are not the same as your element names. However, once you set a new variable, you can use it any place throughout your other calculations just like your element names.

You can also add, subtract, multiply, and divide numbers in your variables. For example:

SET "!NewNumber! = 15 + 1"

Now !NewNumber! will equal 16. However, you cannot define the same variable more than once when calculating numbers. For example, you CANNOT do this:

SET "!NewNumber! = !NewNumber! + 1"

Instead you would do this:

SET "!NewNumber2! = !NewNumber! + 1"

Now !NewNumber2! will contain the added values.

Ordinarily all calculations are processed when the form is submitted by someone visting your web site. However, there may be times you want to set variables before and display them onto your forms. You can start a calculation with BEGIN or GLOBAL to tell $title_tag to process these lines before the form is submitted rather than after.

Let's say you created a survey and wanted to display how many people voted for Apples as their favorite fruit in the footer of your form. You would read from a database and set a new variable like this:

BEGIN: IF ("\U!DB=EmailList,0,||!\E" EQ "APPLES") SET "!AppleVotes! = !DBCOL1!"

You can now place !AppleVotes! in the footer of your form, and the actual number of votes in your database will be displayed.

BEGIN: processes calculations before a form is displayed on your web site.

GLOBAL: will process calculations both before a form is displayed and after it is submitted by someone.

Letting visitors download files

$title_tag has a simple command to begin a file transfer. By default all files that are uploaded are placed in the files folder under $title_tag's main folder. Let's say you have a form that allows your visitor to choose a file to download, and the element name is !DownloadFile!. Your calculation might look like this:

IF ("!DownloadFile!" EQ "myPicture.jpg") DOWNLOAD "files/myPicture.jpg"

So if the visitor selected the file named myPicture.jpg it would begin downloading for them. You can also use the element name in the download command. Like this:

IF ("!DownloadFile!" NE "NONE") DOWNLOAD "files/!DownloadFile!"

This calculation is saying, as long as the value of !DownloadFile! is not NONE, then the download will send whatever file the visitor has chosen.

Sending E-mails

After a form is submitted, it's sometimes very useful to confirm what they have submitted by sending them an e-mail message. $title_tag makes this very easy using the EMAIL command. It's made up of four parts: FROM, TO, SUBJECT, BODY. Here's how it looks:

EMAIL "from,to,subject,body"

Let's say someone signed up for your newsletter and they entered their e-mail address in the element named !Email!. Your calculation might look like this:

IF ("!Email!" NE "") EMAIL "your@address.com,!Email!,Your Newsletter Subscription,Thanks for joining!"

They will now receive an e-mail message from your@address.com with the subject Your Newsletter Subscription, and then the body simply saying Thanks for joining!

$title_tag also allows you to import a text file as the body of your e-mail message. To do that, the command looks like this:

EMAIL "from,to,subject,FILE:filename"

Instead of writing the body of the message message in the command, you tell $title_tag that you want to import the file using FILE: and then the name of the file you want to import. All imported files will be from the email folder under $title_tag's main folder. Here's an example of how you might import a file:

IF ("!Email!" NE "") EMAIL "your@address.com,!Email!,Your Newsletter Subscription,FILE:newsletter.txt"

You can also put your element names in the text file so the values will be filled in. For example, let's say your form has an element named !FirstName! and in your text file you have Hello !FirstName!. Your visitor filled in their name of John. When they receive the email, it will now say Hello John.

You might also want to track e-mail messages using the visitor's IP Address, date, or time. You can use $title_tag's internal variables to add any of them to an e-mail message. They are:

!FORMIPADDRESS!
!FORMDATE!
!FORMTIME!
!FORMMONTH!
!FORMDAY!
!FORMYEAR!
!FORMHOUR!
!FORMMINUTE!
!FORMSECOND!

Sending Visitors to other web sites or forms

$title_tag's GOTO command can do three things: send people to other web sites, send them to another form you created, or end processing.

Let's say you want to send some to a web site. You could simply do this:

GOTO "http://www.cgiconnection.com"

Now let's say you wanted to send them to another form. You would just enter the form name instead of a web site address. The form project must exist in order for this command to work properly. So, if you wanted to send them to Bank_Form2 you would do this:

GOTO "Bank_Form2"

But what if you just wanted to end processing of any other commands after the visitor entered their name? You could do this:

IF ("!Name!" NE "") GOTO "END"

Reading from Databases

$title_tag can read and compare values in your forms to values stored in your text database files. These files are read from $title_tag's databases folder on your web site. You can use the databases created with $title_tag or you can make your own and place it in the databases folder. Keep in mind that $title_tag can only read from one database at a time. When you reading and writing from databases, your IF calculation must begin with a database calculation.

There are three (only two are required) parts to tell $title_tag that you want to read from a database. They are used like this:

"!DB=database_name,column,delimiter!"

  1. database_name is the name of the database you want to read from
  2. column is the column number that you want to compare the element value to (Starts at 0). You can use * to search all columns
  3. delimiter are the character(s) that separate each column in your database. Default is ¦¦ if you do not specify
Here's an example:

Let's say your database columns are separated using two pipe characters, which is $title_tag's default delimiter, and your database contains this line:

JOE¦¦SMITH¦¦212-555-8078

Now we add a calculation to read from the database until a match is found. Like this:

IF ("!LastName!" EQ "!DB=mydatabase,1!") PRINT "Found your last name in database"

$title_tag now searches through the database, mydatabase, and compares the value entered by the visitor in the element, LastName, to column #1, which is SMITH. Remember $title_tag starts searching columns at position 0.

So, if the visitor enters SMITH, they will see Found your last name in database in their browser.

$title_tag stores all columns in special in a special variable named !DBCOL#!. Where # is the column number you want the value of that is in your database. So let's say you want to display the phone number for the example above. Your calculation might look like this:

IF ("!LastName!" EQ "!DB=mydatabase,1!") PRINT "Your phone number is !DBCOL2!"

This time when SMITH is entered, Your phone number is 212-555-8078 will be displayed.

Here's another example:

Let's say your database has a list of e-mail addresses, and looks like this:

sales@bobshardwarestore.com-Bob Walton
cathy@cathyscorner.org-Cathy Christian
john@johnspartyplace.com-John Smith

Your calculation might be like this:

IF ("!EmailAddress!" EQ "!DB=mydatabase,0,-!") PRINTEND "You are already on our mailing list."

So if John Smith comes to your web site and tries to enter his e-mail address of john\@johnspartyplace.com, $title_tag will display You are already on our mailing list., and stop any further processing.

Now it's very possible John Smith will not enter his e-mail address exactly the same way. He might use capital letters, such as John\@JohnsPartyPlace.com. To tell $title_tag to ignore the case, your calculation would look like this:

IF ("\U!EmailAddress!\E" EQ "\U!DB=mydatabase,0,-!\E") PRINTEND "You are already on our mailing list."

Writing and Updating Database Records

Now that you've seen how to read from a database, let's see how to write new records to a database. Keep in mind that $title_tag can only write or update one database at a time.

Let's say you want to create a database of names and e-mail addresses of people that sign up for your newsletter. Here's how we would check if the e-mail address is in the database, and if not, add it.

IF ("\U!DB=EmailList,0,¦¦!\E" NE "\U!Email!\E") WRITE "DB=EmailList,,¦¦::!Email!¦¦!Name!"

The first part of the calculation searches through column 0 where the e-mail addresses are and compares it with what the user entered in the !Email! element. We convert the values to uppercase using \U\E so no matter how the visitor enters their e-mail address, it will be found.

The WRITE command will add the new record if the e-mail address is not in there. So, just like reading from a database, we tell $title_tag the name of the database and how to write the record. You do not need to specify the column number because we are adding an entirely new record. However, you should always specify the delimiter. So, we start the command exactly the same as when reading from the database:

WRITE "DB=EmailList,,¦¦

Next we separate the database information with the record information using two colons. Like this:

WRITE "DB=EmailList,,¦¦::

Now we enter the element names that will be added to the database, and separate them with our delimiter. In this case it is ¦¦

WRITE "DB=EmailList,,¦¦::!Email!¦¦!Name!"

So let's say Bob entered his e-mail address as bob@bobshardware.com. The record in the EmailList database would now look like this:

bob@bobshardware.com¦¦Bob

Ok, so we've seen how to add a new record to a database. Now, what if you want someone to update their e-mail address that you have on file?

Let's say you have two elements on your form. One named !CurrentEmail! that asks your visitor for their current e-mail address, and another named !NewEmail! that asks the visitor to enter their new e-mail address. The calculation would look like this:

IF ("\U!DB=EmailList,0,¦¦!\E" EQ "\U!CurrentEmail!\E") UPDATE "DB=EmailList,,¦¦::!NewEmail!¦¦!DBCOL1!"

$title_tag will search through the EmailList database exactly like the WRITE command, and if the current e-mail address is found, then it will be updated. The only difference is the UPDATE command will keep other columns the same if you choose to. So, updating the e-mail address and leaving the name in the database the same would look like this:

UPDATE "DB=EmailList,,¦¦::!NewEmail!¦¦!DBCOL1!"

Again we specify the database name without the column number and with our delimiter, but you must specify each column number you want to stay the same by using $title_tag's internal variable !DBCOL#!. # is the column number you want to place in the database. In this case, the new e-mail address is written in column 0, but the same information in column 1 stays the same.

So, let's say Bob returned to your web site and entered his old e-mail address of bob@bobshardware.com and his new address of bob@bobsnewhardware.com. Since his e-mail address is already on file, and we don't want to change his name, his new record will simply change to:

bob@bobsnewhardware.com¦¦Bob

You could have let Bob change his name to Bobby by doing something like this:

UPDATE "DB=EmailList,,¦¦::!NewEmail!¦¦!Name!"

In this case, our new record would change to:

bob@bobsnewhardware.com¦¦Bobby

Combining commands

Sometimes you might want an action to take place immediately after writing or update your database, rather than processing another calculation. For example, if a person signs up for your newsletter, your calculation might look like this:

IF ("\U!DB=EmailDB,0,¦¦!\E" NE "\U!Email!\E") WRITE "DB=EmailDB,,¦¦::!Email!¦¦!Name!" : PRINTEND "Thank you for joining our newsletter"

Notice at the end of this calculation there is a colon (:) and another command. You can use PRINT, PRINTEND, PRINTARRAY, READ, GOTO, SET, EMAIL, or DOWNLOAD. When using databases, the first command must begin with a WRITE or UPDATE statement to combine other commands, otherwise the database will not be written to.

Here's an example of setting multiple variables and printing them in a single statement:

SET "!First! = John" : SET "!Last! = Smith" : PRINT "Your name is !First! !Last!"

When this line is processed, it will display Your name is John Smith.

Reading files into memory

To read a file into memory, it must be placed in one of $title_tag's subfolders. Let's say you have a file named Book.html in the folder files. $title_tag can read Book.html into a variable like this:

READ "!Book!=files/Book.html"

You can now print the information back to the screen with the PRINT or PRINTEND command:

PRINT "!Book!"

Reading databases into memory

Loading a database in memory is similar to writing or updating your databases. Only this time, you tell $title_tag which variables should contain the loaded information. These variables should not exist any place else in your calculations or as Element names. Here's an example:

IF ("!LoadDB!" == "1") READDB "DB=EmailList,,¦¦::!NameDB!¦¦!EmailDB!"

Now !NameDB! and !EmailDB! will contain all values from each column of the EmailList database. You can display the information by using the PRINTARRAY command. Like this:

IF ("!LoadDB!" == "1") PRINTARRAY "0-0::Name: !NameDB! <br> E-mail: !EmailDB!"

Just like reading and updating databases, the columns are read in from position 0. The portion before the double colon (::) tells $title_tag which column to start and end with. 0-0 means to display all lines.

So, if you put 1-2, then the second line and third line of the database would be displayed. The second number tells $title_tag to display two lines starting with line 1.

But what if you only wanted to display the last 5 lines of the entire database? In this case, you use a negative number. Like ths:

IF ("!LoadDB!" == "1") PRINTARRAY "-5::Name: !NameDB! <br> E-mail: !EmailDB!"

Now when any of these calculations are run, they will display something like this:

Name: Bob
E-mail: sales@bobshardwarestore.com

The same line will be printed with different database information until all lines that you specified are shown.