Persistent data across web forms: Sessions |
Try online | Examples |
Warning: Native session support has been removed with Aptilis 2.4 RC1. Please use apt.util.Session from the library instead. |
This example illustrates how simply you can go with forms by using the _Session global variable which is kept across forms. Before you embark upon using that feature like crazy, make sure you know the whole story by reading 'Persistence of data across web forms' as there are a few restrictions.
The example given here is of a typical process to get a sales prospect's details.
The example has taken it to the extreme and you will note that the 'Back'
button of your browser defeats the process. The cure to that, is of course,
to pass the stage the user's in as a hidden field rather than storing it
in _Session[0].
Here's the source of the aptilis program:
Note how quite simple this is!
sub main
print("Content-Type: text/html\n\n")
print("<HTML>\n<HEAD>\n\t<TITLE>Session based form</TITLE>\n</HEAD>\n\n")
print("<BODY bgcolor=\"#FFFFFF\">\n\n")
if reset
_Session[0] = 0
end if
print("<FORM action=\"http://localhost/cgi-bin/aptilis.exe\" method=\"POST\">\n")
print("<INPUT type=\"hidden\" name=\"file\" value=\"f:/projects/aptilis/documentation/targets/local/scripts/session.e.txt\">\n\n")
select _Session[0]
case 0
_Session[0] = 1
print("<B>1. Personal details</B><BR>\n")
print("Please input your name: <INPUT type=\"text\" name=\"s1Name\"><BR>\n")
print("<INPUT type=\"submit\" value=\"next\"><BR><BR><BR>\n")
break
case 1
_Session[0] = 2
_Session[1] = s1Name$
print("<B>2. Quick contact</B><BR>\n")
print("Please input your e-mail: <INPUT type=\"text\" name=\"s2Email\"><BR>\n")
print("<INPUT type=\"submit\" value=\"next\"><BR><BR><BR>\n")
break
case 2
_Session[0] = 3
_Session[2] = s2Email$
print("<B>3. Where to send the goods</B><BR>\n")
print("Please input your postal address: <TEXTAREA name=\"s3Addr\" cols=30 rows=6></TEXTAREA><BR>\n")
print("<INPUT type=\"submit\" value=\"Finish\"><BR><BR><BR>\n")
break
case 3
_Session[0] = 0
print("The following information:\n")
print("<TABLE border=1><TR><TD>")
print("Name: ", _Session[1]$, "<BR>\nE-mail: ", _Session[2]$, "<BR>\nAddress: ", s3Addr$)
print("</TD></TR></TABLE><BR>has been sent to the Jelly© Corp. Of San Blobino, Ca. for assessment. You should receive your jelly sample in the post before the end of this decade or the next.")
end select
print("</FORM><BR>\n<BR>\n")
print("</BODY></HTML>")
end main
Things learnt