It looks like you're new here. If you want to get involved, click one of these buttons!
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
/modules/partners/model/Partner_model.php
class Partner_model extends Base_module_model {
function form_fields($values = array(), $related = array())
{
$fields = parent::form_fields($values, $related);
$this->form_builder->set_params([
'exclude' => [
'field_to_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
/modules/partners/controllers/Partner.php
<?php
class Partner extends CI_Controller {
var $partner_config;
function __construct()
{
parent::__construct();
}
/**
* Submit a new Partner Entry
* @return void
*/
function submit()
{
$this->load->model('partner_model');
$this->load->library('form_builder');
$this->form_builder->initialize(array(
'form_attrs' => array(
'method' => 'post',
'action' => '/partner/submit'
),
// different exclude setting
'exclude' => ['other_field_to_exclude','foo']
));
$fields = $this->partner_model->form_fields();
$this->form_builder->set_fields($fields);
// excluded fields are ignored instead it hast the settings of partner_model.excluded
$this->form_builder->render(),
}
}
But I can't set exclude fields here in the submit() method.
Any idea?
Comments
Got it, I need to load
before
$this->form_builder->initialize
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!
[1] How can I see what validation rules from the model are applied? (http://docs.getfuelcms.com/libraries/my_model) => 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:
CI()->lang->language['data_saved'] = 'New Success Message';
You can call it withlang('data_saved')
. It's using a CI session flash notification to render and you will need to add that code to your controller.