I've been wanting to try building user forms for a CMS straight from what I know about a mysql table before, but have never got around to it.
I've discovered that I can find out A LOT about each column using the mysql_field_*() functions, which is great. However, where I'm stuck is that not every field should be displayed to the user (like an auto-increment ID). I first though column comments would help, but they're a MySQL 4.1+ feature that I don't / won't have the luxury of.
My simple idea was to place a _usr on the end of column names which I expected user input from, then only building a HTML form to suit THOSE columns. This worked fine.
Then I decided that some fields would be required, and others would not. I also decided that some fields would require basic cleaning (strip tags), but others would require complex parsing (bbcode for example) before insertion.
I had a pie-in-the-sky idea that I could name MySQL columns WITH instructions in them for what my application should do...
bodyText_URB
could mean that it's for the User to fill in, it's Required, and should be parsed with a BBCode parser.
bodyText_URH
could mean that it's for the User to fill in, it'd Required, and basic HTML is allowed inside.
I like the fact that everything I need to know about a column / field is listed in one place -- it isn't split into the PHP script as well. However, this also means I'm putting application logic in the data layer, and creating a legacy field name that may have to be changed at some point when I decide a 'H' should be a 'B', or an 'R' is no longer required.
Perhaps all the user-supplied data could be in a separate table, but that would only solve some of my problems.
So, looks like I'm back to PHP logic.
I considered that I could store a simple array of required/user/bb/html/etc field names to which I could check against when building the form from the mysql data, but my hope is that someone else has tackled something like this in the past, and can offer some advice...
TIA Justin French
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php