Personal tools
You are here: Home Products PloneFormGen Documentation Tutorials Simple SQL CRUD With PloneFormGen Database Table & Form
Document Actions

Database Table & Form

In this step, we create a simple database table and a matching form.

Steve McMahon

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

The database

Hope you're not feeling too ambitious at the moment, because this is going to be a very simple demonstration table. It's going to have just three columns:

uid
A unique ID that's the primary key for the table. We'll make it auto-increment so that our SQL server (MySQL in this case) will do the work of keeping it unique.
string1
A simple string.
string2
Another simple string.
(I told you this was simple!)

Create a test database and then the table. In MySQL, the CREATE code to set up the table is:
CREATE TABLE simple_db (
uid bigint(20) unsigned NOT NULL auto_increment,
string1 varchar(255) NOT NULL default '',
string2 varchar(255) NOT NULL default '',
PRIMARY KEY (uid)
) TYPE=MyISAM;

Now, set up an SQL user with privileges adequate to select, insert and update the table. Use that user identity to set up an SQL database connection object via the ZMI. (If you're using MySQL, this would be a Z MySQL Database Connection.) The connection must be in a place where it will be visible to the form you'll be creating.

The form

Now, create a PloneFormGen form with three fields:

uid
An string field with id uid, marked hidden, with a default value of "-1". Later in the tutorial, we'll use the "-1" as a marker value to indicate a new record.
string1
A string field with id string1.
string2
A string field with id string2.
Note that the form field ids must exactly match our column ids. You can script your way around this requirement, but it's a lot easier this way.

While you're at it, turn off or delete the mailer action adapter. It's harmless, but it would be a distraction.

That's it. We now have a form that matches our database table.

 
by Steve McMahon last modified March 7, 2007 - 03:00

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by