CGI-Driven Rule Sets

Top  Previous  Next

The UnForm job that runs is a rule set named in the args variable of the HTML form, with the -f rulefile -r ruleset options.  A sample rule set is defined in the samples/cgiforms.rul file, called "approval".

 

[approval]

prejob{

       approved=num(cgi.approval$)

       cgiresponse$="Approved"

       if not(approved) then cgiresponse$="Not approved"

}

 

In this very simple rule set, a value is sent from the HTML form field "approval".  This field is a radio button with a value of 0 or 1, depending on which button is checked (see the HTML sample above for the HTML form coding used).  The variable cgiresponse$ is set to a text value that is returned to the browser.

 

Alternatively, if cgiresponse$ is not set, then the job's output is returned to the browser.  In this case, the HTML form would specify a "-r approval2" and "-p pdf" in the args variable.  The result will be a simple PDF document with text indicating the value of the approval field.  Note that the print stream data contains data communicated to the rule set that is normally of no use to the user, hence the use of the notext command to suppress print stream text.  Other techniques might be code block resets of the text$[] array, or an erase command.

 

[approval2]

prejob{

 approved=num(cgi.approval$)

}

notext

text 10,10,{"Approval: "+str(approved)},cgtimes,12

 

 

There are three template strings provided to code blocks in a CGI-driven rule set:

 

cgi$ contains all the form fields that are present in the HTML form.  All cgi$ fields are string fields, so all are accessed as above: cgi.field$.
 
cgienv$ contains the CGI environment variables, if needed, such as cgienv.script_name$ and cgienv.remote_host$.  CGI environment variables are documented in many places on the Internet and in numerous books on web scripting.
 
cgisession$ contains fields related to the user's session.  Of particular note might be the user login ID, which is found in cgisession.s_userid$.