Syntax: By Example



The following script is the form 'form.able' from the Quick Start page. Here, it is explained in a step by step walk-though.

The color codes in the script are as follows:


<html>
	<head>
		<title>Flex-Able: Form Processing</title>
	</head>
<body>
<center><h1>Test Form Processing</h1></center>

<h2>The field values are:</h2>
<:set myForm <:read_form>>
<ul>
Form.able starts by setting up a variable called 'myForm' to read the form via the read_form command. The variable 'myForm' becomes a container of all the data submitted to Flex-Able from the HTML form fields, so that other commands can access it with the newly created 'myForm'. 'myForm' is now a variable of type form_read, containing all the information from the HTML form who's action points to this script.
<:foreach name value myForm>
	<:echo "<b>" name "</b>:" value " (" <:type_of value> ") <br>">
This section formats the field data and puts it in the response page. For each of the 'name' and 'value' arguments that typically come out of an HTML form, Flex-Able exchanges the actual name of the field (e.g. 'Field1') for 'name' and the value entered by the client into that field for 'value'. During each process, echo puts the info into the stream- in this case, into an HTML response page. Within the echo command, type_of extracts the type of form data from 'value' (e.g. radio/check boxes, text fields, etc).
	<:ifequal <:type_of value> "FSSP">	
		<blockquote><pre><:include_file value></pre></blockquote>
While checking each of the values with foreach, ifequal checks to see if any of the values entered by the client are of type FSSP- files. If they are, include_file inserts the contents of the file between blockquote tags.
	<:/ifequal>
<:/foreach>
</ul>
<P>

<h2>The checkbox values are:</h2>
<ul><:foreach name value myForm["checks"]>
	<:echo "<b>" name "</b>:" value "<br>">
<:/foreach></ul><P>
This time, foreach uses an argument to process only the fields named 'checks' in the HTML form. The same could be done for the other list, called 'choices', by replacing the argument in foreach. Multiple arguments can be added to foreach as well- a good way to seporate different data from a single form.
</body>
</html> 



back to Contents /