Personal tools
You are here: Home Products PloneFormGen Documentation Tutorials Simple SQL CRUD With PloneFormGen Inserting rows

Inserting rows

In this step, we create a method to insert a row, and show how to make simple use of it.

A step-by-step lesson in using PloneFormGen to read, insert and update rows in a single SQL table.
Page 3 of 6.

Now, inside the Zope Management Interface, in your form folder, create a Z SQL Method with the id testCreateRow.

Set the parameters:

Connection ID
This should be the database connection you set up to allow access to your test database.
Arguments
On separate lines, specify "string1" and "string2". (Leave off the quotes.)

Then, in the big text area, specify the code:

insert into simple_db values (
0,
<dtml-sqlvar string1 type=string>,
<dtml-sqlvar string2 type=string>
)

Note: always use <dtml-sqlvar ...> to insert your variables. It protects you against SQL-injection attacks by SQL quoting the values.

Now for a little magic: Z SQL Methods can pick up their arguments from REQUEST.form, which is exactly where Zope is putting your form variables when you submit a form. That means that you can just go to the [overrides] pane of your Form Folder and set "here/testCreateRow" as your After Validation Script.

Your form will now store its input into your SQL table! Add a few rows to check it out.