Form in Backend and Frontend

I build an advanced module with an extensive form in the backend that I want to display partially in the frontend (User register in the frontend and admin approves and changes in the backend.)

I setup my model in the backend and now I attempt to load the model in the frontend


class Partner_model extends Base_module_model {
    function form_fields($values = array(), $related = array())
        $fields = parent::form_fields($values, $related);

            'exclude' => [

        // do something to the fields

        return $fields;

Then I load my model in the frontend, to have access to all the form fields from the database

class Partner extends CI_Controller {

    var $partner_config;

    function __construct()

     * Submit a new Partner Entry
     * @return void
    function submit()


            'form_attrs' => array(
                'method' => 'post',
                'action' => '/partner/submit'
            // different exclude setting 
            'exclude' => ['other_field_to_exclude','foo']

        $fields = $this->partner_model->form_fields();


        // excluded fields are ignored instead it hast the settings of partner_model.excluded


But I can't set exclude fields here in the submit() method.

Any idea?


  • Got it, I need to load

    $fields = $this->partner_items_model->form_fields();

    before $this->form_builder->initialize

  • edited November 2018

    What is best practice to share a model with frontend? reusing all the hooks etc? Is that possible without problems? What if I use $this->fuel->admin->set_notification in the hook? That wouldn't work in the frontend?!

  • I'm just going to talk to myself here, sometimes it helps writing things out :). If someone can help, that would be great!

     * Submit a new Entry
     * @return void
    function submit()
        // needed for the flash data
        $this->load->library('MY_Form_builder'); // extended Formbuilder to do some extra stuff
        if (!empty($_POST))
            // getting my models validation object
            // [1]
            $validator = $this->partner_items_model->get_validation();
            // add some extra rules for frontend
            $validator->add_rule('cat', 'required', "Das Feld Kategorie muss ausgewählt werden", array($this->input->post('an_kategorie')));
            // save
            $saved = null;
                // calculate some stuff in the models hook
                #$_POST = $this->partner_items_model->on_before_clean($_POST);
                // what else is recommended here? Sanitize the input?
                // save entry to db
                // [2]
                $saved = $this->partner_items_model->save($this->input->post());
                    // send Partnerobject see Blog.php:345
                    // create new entry
                    // TODO: send E-Mail to Admin and evt. user
                    $notified = $this->_notify($partner);
                // TODO: Show success Message
                // [3]
            // TODO: Show errors, how?
        $exclude = [];
        // load fields first
        $fields = $this->partner_items_model->form_fields();
        // exclude some fields and sections
        $fields = array_diff_key($fields, array_flip($exclude));
        // then init form_builder and overwrite exclude fields etc
            'form_attrs' => array(
                'method' => 'post',
                'action' => '/partner/submit'
            'no_css_js' => TRUE, // don't load Fuel backend JS/CSS
            //'js' => $js,
            'submit_value' => '<button type="submit" name="submit_form" class="btn btn-info">Eintrag absenden</button>',
            'textarea_rows' => '5',
            'textarea_cols' => '28',
            'exclude' => $exclude,
            'display_errors' => TRUE,
            // Render Form Options
            'render_format' => 'divs',
            'label_layout' => 'left', //top|left
            // only in my_form_builder
            'bootstrap_field_col_classes' => 'col-sm-7',
            'bootstrap_label_col_classes' => 'col-sm-3 col-form-label'
        // render und process form.
        $vars = [
            'form' => $this->my_form_builder->render_bootstrap_divs(),
            'layout' => 'kiosk', // !needed
            'page_title' => 'Partner senden',
        // @link
        // @link
        $output = $this->fuel->pages->render('submit', $vars,[
            'view_module' => PARTNER_FOLDER,
            'language' => 'de'
        ], True);

    [1] How can I see what validation rules from the model are applied? ( => auto_validate, auto_validate_fields, required. How can I use as much FUEL methods as possible?

    [2] Or are all validation rules from the model are applied in the model->save() method? How can I check which rules are applied here?

    [3] Do I have access on the Fuel success message? (Which is used in the backend)

    [4] What about errors? Are they automatically attached to the rendered form from the form_builder or do I have to assign them to my template myself?

    I looked up the frontend stuff from the blog module, because this comes the closest to what I want to do (send/save a form), but there is so much back and forth in the code, that it is hard to follow. And sometimes the docs just miss proper examples.

    Please advise how to proceed from here.
    Thanks so much!

  • 1 & 2. In the model's on_before_save hook, try adding the following and click save:

    echo '<pre>';
    echo '</pre>';
    1. The fuel success message is in the fuel/modules/fuel/language/english/fuel_lang.php file and I believe can be accessed and altered as so CI()->lang->language['data_saved'] = 'New Success Message'; You can call it with lang('data_saved'). It's using a CI session flash notification to render and you will need to add that code to your controller.
    2. Errors should automatically get set on the Global errors object which the Form_builder object will use by default.
Sign In or Register to comment.