Form generation and validation framework

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Form generation and validation framework

Post by josh »

So I'm playing around with writing a data mapper to use doctrine models with zend form, I'm having an issue with doing hierarchical data. Im trying to represent the depth of a category in a category tree by prefixing it's name space characters ( I used underscores instead of spaces for formatting here )

<option value="6" label="_____Test7" selected="selected">_____Test7</option>

code looks like this

Code: Select all

 
foreach( $tree as $node )
{
            $field->addMultiOption( $node['id'], str_repeat( str_repeat('&nbsp;', 5 ), $node['level']) . ucwords($node['name']) );
}
Poblem is zend escapes my input for me, assuming noone would ever use HTML in an input value... I guess this means I'd have issues editing HTML in a textbox with zend form as well? If i just put a ' ' space character the spaces get outputted in the source HTML but the browser ignores them, also I need to be able to have rich form controls with more then just text as values, what form generation tools are the most robust that anyone has experience in?

I'm trying to just get a simple CRUD framework for myself going, where all I have to do is define models, and set a boolean to if the admin should be able to manage categories for that model. What I'm doing now is looking at the metadata of the doctrine active record object, iterating over the fields skipping fields I don't want on the current form ( I have a global list of "blacklisted" fields ).. works for prototype purposes but obviously this thing needs to be more powerful then that.

I was thinking a good solution would be to set up XML files or ini files that specify which fields should be ignored as far as showing them to the user, also some models may have many fields and I may only want a certain set of default fields in the "browse" or "list" screen.

Is there any way with doctrine, or any other tool to do what I'm talking about? Right now my schema looks like

Code: Select all

 
ContentVideo:
    tableName: videos
    actAs:
        SoftDelete:
        Timestampable:
            created:
                name: created_at
                type: timestamp
                format: Y-m-d H:i:s
            updated:
                name: updated_at
                type: timestamp
                format: Y-m-d H:i:s
    columns:
        id:
            primary: true
            autoincrement: true
            type: integer(50)
        title:
            type: string(255)
        description:
            type: string
 
for instance here, when iterating an active record object my application is exposed to the behavior specific fields 'deleted', 'updated_at', etc... which I don't want on my edit form, ideally this would be encapsulated so I wouldn't have to block out these fields manually... the metadata doesn't differentiate between a templated / inherited field or a concreate field

I want to also tell it which fields should be used in certain views, I looked over all documentation for my frameworks several times and searched for an answer as best I could, is there a cleaner way then setting up my own parallel schema files.. I mean if it came down to that I could have my schema files generate the doctrine schema for me, and just define it one place, but that seems a little redundant

All of doctrines code generation stuff is built into their API so you don't have to use physical schema files, I could implement my own schema that has model specific and form specific schema, and passes only the model schema to doctrine.. but it seems like a tool has to already exist for this

Is this an invention or an implementation? Does this exist?

i could just write parallel form schema files and load them into zend_form with zend_config, but that just seems so... tedious
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Form generation and validation framework

Post by josh »

Perhaps this is coupling of storage and business logic? Can anyone tell me if this makes sense?
I'm going to just use zend_config to configure the form properties instead of flagging them somehow within doctrine, as at the time it doesn't seem possible without a bunch of painful hacks
Post Reply