next up previous contents
Next: MICdo Up: Sample Code Previous: Sample Code   Contents


Embedded Logic

Consider the following snippets:

from login.html:

...
Please enter your user name and password:
<form action="check_password.mic">

User Name:<input name="username" type="text"><br>
Password:<input name="password" type="password"><br>

<input name="login_submit" type="submit" value="Submit">

</form>
...
*******
from check_password.mic:
...
<MICif test="check_login($cgi-&gt;param('username'),
			  $cgi-&gt;param('password'))">
  return Pile::example::index($cgi);
</MICif>
<MICelse>
  return Pile::example::login($cgi);
</MICelse>
...
*******
The above example illustrates the use of simple embedded logic, calling pages as functions, and the use of HTML forms within MIC (which is trivial). In the above example, we are using a direct CGI call to check the value of the fields, which is discouraged in general, but may be appropriate in certain cases (see 3.2.2. The above, in particular, is a bad example in that respect as far as the style guidlines are concerned.

On the basis of the result of the function check_login, we either return the index page or return to the login page. Note that the browser will believe that the page being displayed is called `check_login.mic,' but since all three of the pages of concern are at the same directory level, this is okay as far as functionality is concerned.