Programming a Module Button to display a custom form in the Fuel Admin layout

edited January 2014 in Modules
I'm following along this helpful tutorial that shows how to use the Form Builder class to create a custom form, but rather than render the form raw as in this example, I'd like to render the form inside the FuelCMS admin instead.
http://www.sitepoint.com/getting-started-with-fuel-cms-2/

I have an "Orders" module that when an order is clicked, a "Refund" button appears at the top for that item. When Refund is clicked, I want a custom form to display within the Fuel admin for filling out a refund form. How would I go about modifying this code to render the form in the Fuel admin layout?

$this->load->library( 'form_builder', array( 'id'=>'addComment', 'form_attrs' => array( 'method' => 'post', 'action' => 'refund' ), 'submit_value' => 'Refund', 'textarea_rows' => '5', 'textarea_cols' => '28' ) ); $fields = array( 'name' => array( 'label' => 'Amount', 'required' => true ), 'notes' => array( 'type' => 'text', 'label' => 'Notes', 'required' => true ) ); $this->form_builder->set_fields($fields); echo $this->form_builder->render();

Comments

  • edited 9:32AM
    It sounds like you need one form for your orders, and a second form for the refund. For the orders form, I would use your orders model's form_fields method like normal and perhaps add a button as one of the fields or a link that someone could click on to trigger the refund form.

    For the refund form, you'll need to create your own controller and add the form there. I just did this for a project where I had a projects_model that needed to trigger a modal window that displays who to notify. The who to notify was a series of checkboxes outside of the context of the orders and needed its own form. I wound up creating everything in it's own advanced module (outside of the application directory... for portability), and created a controller that would display the proper form there. To trigger the modal, I wound up using the module's js_controller and js_controller_path values to specify where to load the javascript code that would control the modal window. Below is code for the module configuration as well as the javascript I used:

    // located in a folder called fuel/modules/proofer/config/proofer_fuel_modules.php
    $config['modules']['projects'] = array( 'preview_path' => 'proofer/view/{client_id}/{slug}', // put in the preview path on the site e.g products/{slug} 'model_location' => 'proofer', 'module_uri' => 'proofer/projects', 'item_actions' => array('save', 'view', 'publish', 'activate', 'delete', 'duplicate', 'replace', 'create', 'others' => array('proofer/notify' => 'Notify')), 'js_controller' => 'ProoferController', 'js_controller_path' => js_path('', PROOFER_FOLDER), 'filters' => array('client_id' => array('type' => 'select', 'model' => array(PROOFER_FOLDER => 'clients_model'), 'label' => 'Client')), );

    Located in the fuel/modules/proofer/assets/js/ProoferController.js
    ProoferController = jqx.createController(fuel.controller.BaseFuelController, { init: function(initObj){ this._super(initObj); }, add_edit : function(){ var _this = this; // do this first so that the fillin is in the checksaved value //fuel.controller.BaseFuelController.prototype.add_edit.call(this, false); this._super(); // remove current binding from BaseFuelController $('.submit_action').unbind(); $('#notify, .submit_action').click(function(e){ e.preventDefault(); var url = jqx.config.fuelPath + '/proofer/notify/' + $('#client_id').val() + '/' + $('#slug').val(); var html = '<iframe src="' + url +'" id="asset_inline_iframe" class="inline_iframe" frameborder="0" scrolling="no" style="border: none; height: 250px; width: 850px;"></iframe>'; $modal = fuel.modalWindow(html, 'inline_edit_modal', false, null, null); }) } });

    Hopefully this helps some.
Sign In or Register to comment.