May 25, 2011

How to collect data from web visitors and save them in your database

It is very easy to make data collecting web application using the WhizBase. We will do it using only two WBSP files - one containing the form (form.htm) and the other that saves received data into the database (add.wbsp).

Database structure for subscribers.mdb
Table Mlist
FistName Text 50
LastName Text 50
Email    Text 50


File form.htm
<html>
<head>
<title>Subscribe to mailing list</title>
</head>
<body>
<form action="add.wbsp" method="POST">
<table border="1" cellspacing="0"" cellpadding="3" bordercolor="#000000" bgcolor="#FFFFFF" style="border-collapse:collapse;">
<tr><td valign="top"><strong>First Name</strong></td><td valign="top"><input type="text" name="WBF_FirstName" value=""></td></tr>
<tr><td valign="top"><strong>Last Name</strong></td><td valign="top"><input type="text" name="WBF_LastName" value=""></td></tr>
<tr><td valign="top"><strong>Email Address</strong></td><td valign="top"><input type="text" name="WBF_email" value=""></td></tr>

</table>

<input type='submit' value='Submit'> <input type='reset' value='Reset'>
</form>
</body>
</html>


File add.wbsp
<!--
[FormFields]
WB_BaseName=subscribers.mdb
WB_Command=A
WB_RcdSet=mlist
-->
<!--WB_BeginTemplate-->
<html>
<head>
<title>Thank you for subscribing</title>
</head>
<body>
Thank you for subscribing with us!<br>
Added data:<br>
$wbf[FirstName] $wbf[LastName], $wbf[email]
</body>
</html>

As you can see, first file is ordinary HTML file with form, text input fields and submit/reset buttons. Second file is a simple WhizBase program that instruct WhizBase to use the table mlist from database file subscribers.mdb, to add data received in WBF_ form fields and to display added data using $wbf function.

No comments: