Setting up the multi-page form
This form has two pages, an initial entry form where the user adds an email, and the main data submission form.
We want entry for the users to be as simple as possible. If we have existing information for them in our database, there is no reason for them to add that information again. So the first page of the form requests an email address. Then the second page is dynamically populated with values (if they exist) from the database, otherwise the field is blank awaiting user input.
Create the multi-page forms
Follow the how-to instructions here.
After reading this now just:
- Add a the first form folder and add a string field for the email address, call it reg_email
- Add the second form folder and add the fields you want to be submitted to the database.
(remember, follow all the instructions regarding the multipage forms)
Set up the MySQL Details
Your database should have a uid column as in the example. However, in our case we will not use this to query the database, rather we will use the email address provided. Theoretically, the email could be the primary key for the db table, but it's much easier to use an integer, and let MySQL auto_increment the value as you add entries to your database.
Follow the instructions here.
After reading through this, you should now set up the MySQL Methods:
- make the testCreateRow and testUpdateRow Z SQL Methods as shown, but with arguments as you require. One of these will be reg_email
- Now create the testReadRow method as described, but here we will make one change. Rather than using the uid, we will use reg_email and type="string". The new SQL query should look like:
select * from db_table where <dtml-sqltest reg_email type="string">
That's it for SQL Methods, now we create the Scripts:
- The first one will take the email address which was entered on the first page of the form and query the database for values to add to the form fields:
request = container.REQUEST
form = request.form
if form.has_key('reg_email') and not form.has_key('form.submitted') :
res = context.testReadRow().dictionaries()
if len(res) == 1:
row = res[0]
for key in row.keys():
form[key] = row[key]
- The second script does the adding or updating of the database. Note: here we still use the uid as described in the tutorial (don't forget the details about setting the default value of -1 and that's its a string, even though it's an integer in your database ):
request = container.REQUEST
form = request.form
if int(form.get('uid', '-1')) >= 0:
# we have a real uid, so update
context.testUpdateRow()
else:
context.testCreateRow()
Make sure you set the appropriate overides as described in the tutorial and multipage form how-to

