Updated Formation
- Posted by dlib on April 8th, 2008 filed in Formation
Last couple of days I made some updates to Formation and I commited them to Google Code SVN. There are numerous updates and I hope to work out a more elaborate manual as well as finalize some changes as the Element_Multi which is the basis for lists of radio/checkbox elements as well as multi-select boxes.
Changes:
- Numerous bugfixes
- Setting order of form elements afterwards
- Cross site request forgery field - already there in an older release but it’s nice
- Deprecated set_values over populate_form, set_values works as an alias
- Lot’s of other stuff I can’t quite recall
-
- Model_Formation
- db fields preceded with ‘is_’ will turn into checkboxes
- Model formation factory
- ‘Belongs to’ relationship will turn field into dropdown for relations. Needs an id field and a name field (name fields can be emulated with __get)
I quite like the model_formation factory, it works like this:
$form=Model_Formation::factory(ORM::factory('user',1)) ->set_form_fields(array('username','email','description')) ->set_class('user_form');
And you get a form from the user model filled with the user where id=1. It only shows the fields: username, email and description. Model_Validation also retrieves rules set in the model. Again, I hope to document all functionality a little more in the future.
The other thing I’m happy about is the handling of relationships. It’s far from done since only belongs_to is rendered. Anyway, when you have an article model and it belongs to the user and following you have a field user_id in your article table, model_validation will render a dropdown for that field showing you all users you can assign the relationship to. It’s ideal for my CRUD operations. Note that you need a name field in the table you want to link to, you can fake a name field with __get in ORM.
The update is in svn but soon I hope to do some serious cleanups and expand documentation a bit.
9 Responses to “Updated Formation”
Recent Comments
- Rony on Using Auto_Modeler to write quicker code
- priyank Sharma on New design for Kohana sites
- toulon on jQuery and Kohana, unobtrusive Ajax
- Zeelot on HMVC in Kohana
- Learning Kohana » The Form tutorial - the beginning on The Form tutorial - normal Validation
Archives
Kohana Forum Topics
- Announcing Phorm - A Form Generation and Validation Module for Kohana
- Announcing Phorm - A Form Generation and Validation Module for Kohana
- Kohana 2.2, 2.3, and 3.0
- Kohana 2.2, 2.3, and 3.0
- Kohana 2.2, 2.3, and 3.0
- Kohana 2.2, 2.3, and 3.0
- Setting Up a Multilingual Website
- Kohana 2.2, 2.3, and 3.0
- Setting Up a Multilingual Website
- Kohana 2.2, 2.3, and 3.0
April 8th, 2008 at 11:52 pm
i’m testing model_formation but i’m having some problems i can’t sort out.
i’m using latest svn, putting all your code into a module dir named formation & loading it in config.
if i put this code on a controller
i have this result:
Fatal error: Class ‘customer’ not found in /Users/phelipe/Sites/moorea/modules/formation/libraries/Model_Formation.php on line 32
apparently it does’n find the model which - obviously - isn’t in module but in application->models
i’ve also tried with
$form = Model_Formation::factory(ORM::factory(’customer’, $id));
no error but blank form - no fields displayed.
where’s my fault?
thank
April 9th, 2008 at 12:18 am
problem solved: i had another MY_ORM.php in application->libraries, after removing that file the form works.
this lead to another problem: how can i have my personal ORM extension if there’s already a MY_ORM in modules->formation->libreries?
April 9th, 2008 at 7:52 am
Copy your modifications in ORM to the MY_ORM.php It’s the only way. Just make sure nothing clashes.
April 9th, 2008 at 7:56 am
Oh, and
Should be
I’ve been meaning to add your syntax but haven’t had the time.
April 16th, 2008 at 9:35 pm
Do you think it would be possible to rewrite Formation using the official Validation lib for best integration?
April 16th, 2008 at 9:46 pm
You could but the approach would be radically different. I’d create a Formation class and have a validate object within it for the official Validation lib. It would be a complete rewrite though.
Problem with converting Fromation to the validation library is rules, it uses normal callbacks whereas my Validation/Formation lib uses classes for rules. My main reason for doing this that classes allow for error messages like: ‘this field {field} needs {10} chars, you gave me {5}’; I might also implement classes for the filters since it works pretty neat.
I might rename validation to validate though, so the validation lib and my validation lib can coexist peacefully
June 2nd, 2008 at 2:14 pm
Hi! How can I do a radiobutton list? I’ve read the code but I couldn’t find a way to do it. If it’s not ready do you want help? I mean, I really need it and if I do it for me I could contribute to Formation with good php code.
June 2nd, 2008 at 2:49 pm
hey dlib, i’m a little confused; is Formation just an alternative to Forge and the Form library? What are the advantages/disadvantages of each? Why so many ways to do forms?
June 2nd, 2008 at 6:28 pm
Radio buttons are on their way, I’ve already placed a class Multi_Select or something in svn which should replace checkbox groups, multiselect dropdowns etc. If you need a quick fix for radio buttons you could always hack it in with the checkbox groups class and just replace all relevent checkbox code with radio code. It should work although I haven’t tested it.
Formation is an alternative to Forge. It started out of my own need and I released it. For me it offers some advantages over Forge, namely reordering elements, validation as well as filtering, more validation rules (with custom error messages which can be very precise). Rules are classes and it’s easy to add new ones. CSRF protection in forms. Very clear standard Form view. Generator so for the jQuery validation plugin, instant js validation with a few lines of code. It also is a replacement of the validation library and as such offers the same as the Formation library except that it doesn’t generate your forms. It does provide the same rules, filters.
Together with ORM and the- Advanced
- Easy
- Medium
Tags
2.2 Ajax akismet api database django documentation eclipse events example firebug firefox firephp Forge form head hooks image installation jQuery Kohana kohana 2.2 libraries library newbie ORM orm2 pagination pdf profiler release request router routing setup sitemap spam Subversion svn template tutorial unit test url user guide _defaultBlogroll