[an error occurred while processing this directive]
![]() |
Using Conditional (if/else/endif) Processing |
This page introduces the use of conditional processing in WebCom form processor configuration files. More details are also available if you need no introduction and/or for quick-reference.
In some cases you want something defined in your configuration file to happen only if certain conditions are met. For example, on a form which is used to subscribe to an email list, you only want to send the subscription to the mailing list server if the user entered an Email address. If they did not enter an email address, you may want to display an error message. Here's an example of a configuration file which does just that (the details will be explained later):
if ($email_addr eq "") format screen <HTML><HEAD><TITLE>Site - Subscribe to mailing list</TITLE> <H1>You did not enter your Email address! Your email address is required to process your subscription request.</H1> <BR><A HREF="/userid/subscribe.html">Back to the subscription form</A> </HEAD> </HTML> . else format file lists/subscriber_list.txt $email_addr . format screen <HTML><HEAD><TITLE>Subscribe to mailing list</TITLE> <H1>Your subscription to the mailing list has been mailed to the WebCom mailing list server. You will find more info in your mailbox shortly.</H2> </HEAD> </HTML> . endif
The above configuration file is divided into two blocks: the block between the line starting with 'if' and the 'else' line, and the block between the 'else' line and the 'endif' line. The first block is executed if the email address on the form is blank ($form_email_addr eq ""). The second block is executed if the email address is non-blank. You can also define new parameters and set their values, for example:
if ($product_id eq "")
(error message to screen)
$reject="Y"
endif
if ($qty == 0)
(error msg to screen)
$reject="Y"
endif
if ($reject eq "Y")
format screen
<H1>Please return to the previous page, correct the error, and resubmit.</H1>
.
else
format screen
<H1>Your order has been successfully filed! Thank You!</H1>
.
$file=adm/order.dat
endif
[an error occurred while processing this directive]