Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[Discussion & help] Overriding form, fieldset, field and validation
  • Hello, Introduction
    Once again, I'm pushing Fuel to the limits (we all love it!).
    I'm working on overriding form, fieldset and fields to create a new, more powerful form generation base on model properties. Here is a quick screenshot to show you what I generated automatically for now.
    http://www.novius-labs.com/data/photo/45.png So you can see the password field is rendered as 2 separate lines (each one has it's own label and input). And the date field is rendered as 3 inputs (2 text and a select). I don't need to show the code from the Model, it's easy eanough to understand: I just added a 'widget' index in the field properties to know if a widget has to be used for rendering (rather than a standard fieldset_field). Other keys such as "label" and "validation" remains the same.
    Rendering & populating widgets
    I added a new notion called "widget" to allow this. It's used to manipulate one value (1 field from the model) using several fields in the form. For example, I have a Widget_Date class which can be used to manipulate the Date type fields. It renders the field as 3 separates input (text for the day, select for the month and text for the year) and validates them accordingly. What I named "widget" is made of several fields, so I needed a way to :
    - populare and repopulated the widget based on several POST values.
    - build and render the fields accordingly The major modification I made was in the fieldset class : https://gist.github.com/1277711
    It delegates the population of the widget to the widget itself, which can all use the values it needs from the POST array. I needed one small tweak to the form class : https://gist.github.com/1277723
    It delegates the building of the widget to the widget itself. So until there, all is pretty smooth and works well. Validation widget fields
    What I struggle the most with, and I'm the less convinced about is the validation part. I'll take an example to explain it.
    I have a "Password" widget. It displays two input type=password to take care of the verification part. Validation needs to check that both fields are set and matches. From the model perspective it's still a unique password field. My main problem was (is) that when adding a field for validation it also adds a field to the fieldset. I cannot say "I know my form will contains a field named 'whatever' and I want you to check that the value validates". In what I did, the form doesn't necessarily know what will be displayed, because it's sometimes delegated to the widget.A widget can display several input and are seen from the model / form point of view as a unique field (the widget). Here is the password Widget I created : https://gist.github.com/1277747 The Widget_Empty doesn't do anything. It just return an empty string when build, so nothing is displayed in the form. But I needed that to add validation rules without really adding a field because I manage it myself. Discussion
    I explained my problem and how I tried to overcome it. As I'm not completely satisfied I made this post to get feedback and disuss how this can be achieved differently. Or even how can we make Fuel evolve to make this easier. Thanks in advance for everyone who'll take part on this discussion. :-)
  • I didn't explained why I was posting this message on the forum and I didn't introduced myself here before. Sorry about that. I'm working with Gilles Félix, another member of this forum / community. We're software engineers at Novius, a French company, and both of us are currently working full-time on (re)building an open-source CMS using Fuel as a backed framework.
    So we get to use Fuel. A lot. Every day actually. We haven't contribute yet to the project but we are looking forward to it. Not necessarily with pull requests, but also with tutorials and articles on Fuel and how we used / extended it to build the CMS. P.S. I forgot to say: we love Fuel!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion