Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fieldset Class (Use DIV's instead of Table's)
  • Ok whenever I use the Fieldset class, it uses table's... well I hate table's because they are very ugly.
    I researched into the Fieldset AND Form class that comes installed with FuelPHP...
    HOW do you convert the table's into div's??

    Is there some sort of template I'm not seeing? I'm not seeing where they are populating the td's and tr's and whatever.. I want to switch those to DIV's..

    Could someone help me out?
  • The default template used is in config/form.php. If your app doesn't have this, the one in core/config is used.

    Copy it from core/config to app/config, and modify it to your liking.
  • Well it's impossible to edit it the way I would like it since I would like two fields to be within a row.. just not possible with the way they have it set up.. but oh well. :/
    Maybe I'll just setup my own custom form and not use the Fieldset or Form classes.
  • If that's what you want, that's what you should ask. I can't see what it is you want to achieve.

    You don't have to generate the entire form at once, as you have discovered that there are limits to what you can do with a form-wide template.

    You can use $fieldset->build('fieldname') to generate the form field for the variable 'fieldname'. This way you can create the markup for the view manually in the view, including Form::open() and Form::close(), and still use the fieldset to generate the fields (so you can use features like validation).
  • I'm not that great with FuelPHP yet so I have no idea on how I would go about doing that. I took a tutorial to get where I am right now. I've done a lot of research in these classes since I"ve been totally stumped with the markup.. But I'll see if I can figure it out.. I just hope I don't mess things up.

    So my code is like this:
    public function action_index()
        {
            $auth = Auth::instance();
            $view = View::forge('user/register');
            $form = Fieldset::forge('register');
            Model_Register::register($form);
            if($_POST)
            {
                $form->repopulate();
                $result = Model_Register::validate_registration($form, $auth);
                if($result['e_found'])
                {
                    $view->set('errors', $result['errors'], false);
                }
                else
                {
                    Session::set_flash('success', 'User Created.');
                    Response::redirect('./');
                }
            }
            //$view->set('reg', $form->build(), false);
            $view->set('field_username', $form->build('username'), false);
            $this->template->title = 'User » Register';
            $this->template->content = $view;
        }

    But the $view->set('field_username', $form->build('username'), false); is still building the entire form..
  • Don't hesitate to ask, we're here to help if you get stuck.

    If you use build() on individual fieldset fields, the form_method and form_template fields in the template are not used, the others you can strip or change as much as you want to suit your needs.

    Don't forget to copy the file from core/config to app/config before you make changes.
  • Yes I made the changes :)
    I edited my post before your most recent one with some of the code in my controller to generate the form from my model.. but it's generating the entire form still even when I specify which field I want to build and what variable I want to set it at in the view.
  • In your code you do $form->build(), which generates the entire form.

    If you want more granular control, pass $form on to your view. In your view, create the HTML markup for your form manually. Then, insert the individial fields, like so:
    echo Form::open();
    echo '<div id="name">'.$form->field('name')->build().'</div>
    <div id="city">'.$form->field('city')->build().'</div>';
    echo Form::close();

    so you can design it as you want to have it.
  • Wow thank you so much. :) Should my validation stay the same when the form submits if I was using it the other way? How it is in my controller. Would that still stand correctly?
  • From your validation point of view there is no difference, it's still the fieldset.

Howdy, Stranger!

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

In this Discussion