It looks like you're new here. If you want to get involved, click one of these buttons!
<?php
class Quiz extends CI_Controller {
function __construct()
{
parent::__construct();
}
function create()
{
$this->load->library('form_builder');
$fields['language_id'] = array('type' => 'input', 'label' => 'Language Id', 'required' => TRUE);
$fields['category_id'] = array('type' => 'input', 'label' => 'Category Id', 'required' => TRUE);
$this->form_builder->set_fields($fields);
// will set the values of the fields if there is an error... must be after set_fields
$this->form_builder->display_errors = TRUE;
$this->form_builder->form_attrs = array('method' => 'get', 'action' => 'submit');
$vars['form'] = $this->form_builder->render();
$this->load->view('create_quiz', $vars);
}
function submit()
{
}
}
If correct and it seems so, i managed to display a form when i go to
Comments
http://www.getfuelcms.com/user_guide/modules/tutorial
http://www.getfuelcms.com/user_guide/modules/simple
http://www.getfuelcms.com/user_guide/libraries/base_module_model
http://www.getfuelcms.com/user_guide/libraries/my_model
I've already read these several times but as i'm a beginner in learning mode
I created a model for my quiz details I can edit that in the admin backend.
Now I wanted to make that form on my website for end-users
Now I'm looking for examples using form_fields()
I searched the blog code but all i could find was And that doesn't talk to me much
I'm learning as I go too. I get confused between what's available/useable in the admin side vs public code.
Seems it would be very easy for you to continue on your initial post track. Example below. If it was done that way is on_before_save() and the like still available David?
Example. Not really taking advantage of Fuel though. Would make for a useable tut (imo) taking something like that and fuel-ifying it.
<pre> <?php class Quiz extends CI_Controller { function __construct() { parent::__construct(); } function create() { $this->load->library('form_builder'); $fields['language_id'] = array('type' => 'input', 'label' => 'Language Id', 'required' => TRUE); $fields['category_id'] = array('type' => 'input', 'label' => 'Category Id', 'required' => TRUE); $this->form_builder->set_fields($fields); // will set the values of the fields if there is an error... must be after set_fields $this->form_builder->display_errors = TRUE; $this->form_builder->form_attrs = array('method' => 'get', 'action' => site_url('quiz/submit')); $vars['form'] = $this->form_builder->render(); $this->load->view('create_quiz', $vars); } function submit() { $insert['lang_id'] = $this->input->post('language_id'); $this->db->insert('table_name', $insert); } } </pre>
http://www.getfuelcms.com/user_guide/libraries/form_builder
For example, the fuel/modules/blog/models/blog_posts_model.php has a pretty advanced example of what you can do, but just remember, all you are trying to do is create that array that can be handed back to form_builder.
For your controller, you could then load your model and grab the fields array from it's form_fields() method like below: You can also add your validation to the model by specifying the required fields property or using the add_validation() method on the model. Validation is run on save so if it doesn't validate, the save method on the model will return FALSE. For example on your create method, you could add something like: Lastly, to Lance's point, you still have access to all the model hooks (e.g. on_before_save()) for you to do any extra cleaning or validating etc. I hope that helps clarify some.
http://www.getfuelcms.com/user_guide/libraries/validator
With that done, how am i supposed to know what validation step failed and how can I display back the form with error messages ?
Is there something special to be in the view for error messages to appear ?
To get the list of errors back you must use :
$vars['errors'] = $this->quiz_details_model->get_errors();
Is that correct ?
Or should i use :
$vars['error'] = $this->quiz_details_model->get_errors();
$vars['notifications'] = $this->load->view('_blocks/notifications', $vars, TRUE);
$this->load->module_view(FUEL_FOLDER, '_blocks/notifications, $vars, TRUE);