Using fillForm

Try online Examples

FillForm is a very powerful Aptilis predefined sub that will save you a lot of time! It is like Stuff only far more powerful as it understands HTML! This time I'll show you the Aptilis code first:

sub main

	_FormPath = "f:/aptilis/scripts/htmlform-example.html" $

	// As always...
	print("Content-type: text/html\n\n")

	// are the compulsory fields filled with something?
	// (We could use trim before this in case the user has
	// entered only tabs or spaces)

	if len(forename$) = 0 or len(surname$) = 0 or len(email$) = 0

		// If we come back from the form all the values are here in local variables.
		// eg, name, surname, email, language, gender.

		// the template
		form = loadFile(_FormPath$) $

		// we fill it
		readyForm = fillForm(form$) $

		print(readyForm$) // done!

	else

		// All compulsory fields are filled...
		print("<HTML><BODY>")
		print("Thanks. Your details are now going to be processed.<BR>")
		print("(application goes on from here...)")
		print("</BODY></HTML>")

	end if

end sub

Here's what the HTML looks like, it's just a web page:

	<HTML>

	<BODY bgColor="#FFFFD0">

	<IMG Src="http://www.glaine.net/images/aptilis-tiny.gif">

	<P><B>Demo form!</B><BR>
	<I>Don't worry it doesn't keep your details!</I>

	<P>


	<FORM action="/cgi-bin/aptilis.exe" Method="POST">
	<!-- the usual. It will be passed as well! And put back in! -->
	<INPUT type="hidden" name="file" value="c:\aptilis\fillform-example.e.txt">

	<B>Fields in bold are compulsory.</B> For as long as they're not filled,
	you will becoming back here!
	<P><TABLE>
	<TR>
		<TD><B>Name:</B></TD>
		<TD><INPUT type="text" size="20" Name="forename"></TD>
	</TR>

	<TR>
		<TD><B>Surname:</B></TD>
		<TD><INPUT type="text" size="20" Name="surname"></TD>
	</TR>

	<TR>
		<TD><B>Your e-mail address:</B></TD>
		<TD><INPUT type="text" size="20" Name="email"></TD>
	</TR>


	<TR>
		<TD>Language:</TD>
		<TD><SELECT name="language">
		    <OPTION>English</OPTION>
		    <OPTION>French</OPTION>
		    <OPTION>Italian</OPTION>
		    <OPTION>German</OPTION>
		    <OPTION>Spanish</OPTION>
		    <OPTION>Korean</OPTION>
		    </SELECT></TD>
	</TR>

	<TR>
		<TD>Gender:</TD>
		<TD><INPUT type="radio" name="sex" value="female"> Woman<BR>
		    <INPUT type="radio" name="sex" value="male"> Man</TD>
	</TR>

	<TR>
		<TD></TD>
		<TD><INPUT type="submit"></TD>
	</TR>

	</TABLE>

	</BODY>
	</HTML>
Things learnt