Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Form builder custom fields
  • This is more like a proposal, since I think the form builder should be more flexible. 

    Talking about the ability to add custom fields to the form builder. Right now, we are only able to pass pre-defined fields or valid inputs. I came to the situation, where I had to use a "dropzone" thing in my form ( and this wasn't possible without workarounds. I had to create fake field and change it's template within the set_form_fields(..) method:

    'menu_bg'          => [
    'data_type' => 'varchar',
    'form' => [
    'type' => 'text',
    'label' => 'Background',
    Workaround, template field change:
    $form->field( 'menu_bg' )->set_template( str_replace( '{field}', $dropzone,
    $form->get_config( 'field_template' ) ) );

    Maybe it would be a good idea to allow form type=>'template' field so the {field} will be replaced with the rendered template file content and passed parameters will be available & accessible directly as variables within that template file? 

    Maybe the 2.0 form builder will allow that, haven't looked deep into it because I don't want to use it anyways since it doesn't work with 1.8~ ORM/validation classes.

    What do you think?
  • The current fieldset - validation combo is a nightmare from a coding perspecfive. If it works, it works, but it's not very easy to make changes.

    For standard fields, you can use $form->add() / add_after() / add_before() in the controller to add additional fields to the form (that are not defined in the ORM model). 

    We solve your particular problem the other way around, in the view, instead of generating the complete form, we define the form manually, use $form->field('name')->build() to generate the HTML for the fieldset fields, and use regular HTML or the Form class to do the custom stuff.
  • I understand that, but in a bigger project I will have to use dropzone type fields multiple times. It's about 50 lines~ of duplicated HTML code for each input. That is dirty job from practical point of view. 

    Would be awesome if we could've extend the fieldset class just like the controllers to return fields:

    namespace Form;

    class Upload extends Fieldset {
    public function __constructor($options = []) {
    return Theme::instance()->view('templates/upload', $options);

    And use it like:

    $form->add(new Form\Upload(['maxSize' => 2, 'allowExtensions' => ['png', 'jpg']));

    That way, we can for example define allowed extensions once in PHP, pass them to use in the templates for HTML and Javascript without need to keep track of these options in additional files.
  • You can extend the fieldset class, you can extend any Fuel class:

    You can also propose a change to the fieldset class via a github pull request, in which case we can add it to the core. If you want to go this route, discuss your plans up front to avoid rejection, and make sure you adhere to our coding standards (which your snippet does not ;-).

Howdy, Stranger!

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

In this Discussion