Working on a Propel Form Builder…
Tonight I started working on a set of classes that will build forms for Propel objects. While Propel already has implementations of PatForms and HTML_QuickForm, they are both not up-to-date in svn. They both also require Creole for gathering metadata, and I am not at all interested in integrating another library into this project – especially one labeled “dead” on its own site.
I had read recently about using MapBuilder classes for gathering metadata about your tables, and after skimming the api, found the following classes:
- DatabaseMap
- TableMap
- ColumnMap
- ValidatorMap
From the top of the hierarchy (DatabaseMap) you can retrieve an array of TableMap objects, or a singe TableMap by name. You can also get an array of ColumnMap objects in a TableMap, and so on.
The ColumnMap is where most of the relevant metadata lies. It holds column data types (both database and PDO types), related tables, related columns, and can even return foreign or primary key flags. I plan to build the form by data type, using text field for VARCHAR, textarea for TEXT, drop-downs for foreign keys, etc. However what is really neat is the ability to parse input through the validators for a column.
ValidatorMap can return the validator class for a given instance, as well as a value if it exists. So if you have a maxlength validator of value 10, you can call ValidatorMap::getValue() and get back that number. It will return regex as well. This should be very useful for creating client-side validation for the form.
I hope to post back here in a few weeks with a status update, and perhaps a set of classes to try out!