Controller for Page

I have this page which has some text as well as a form. The form is created in a Controller (with a connection to a module, some fields stripped out and some others added).
Now when I try to create a Page for this view it gives me a warning that a controller is connected to it. So the Controller takes over and I put this:
echo fuel_var('body', '<p>some default html</p');
into my view. When the page gets updated in the CMS, the view updates accordingly, so far so good.
However the inline editing pencils don't show up for page variables (they do for sitevariables).
So is this the correct way of doing this, and if yes, what can I do to fix the inline editing?

Comments

  • edited 6:16PM
    And while we're at it.... another question:
    The Controller adds a 'terms' checkbox field to the form fields retrieved from the Module.
    Of course, people must check this box to agree to the terms, so I would like to add a 'required' validation rule to it.
    However this field does not come from the module, so this:
    $this->some_model->add_validation('terms', 'required', 'Please accept the terms');
    doesn't work, as the module only validates fields coming from the module itself (line 1264 in MY_Model.php, validate($record) gets called with a cleaned array containing only the fields from the module)

    So how do I add this rule to the form validation? I can create a new validator, but the Form Builder accepts only one, which is $this->some_model->get_validation() right now, can I combine the two?

    It's really fun to dive in and explore all this stuff, but sometimes it's a little too hard ;)
    Anyway, thanks for all the hard work so far, it's a great cms!
  • edited 6:16PM
    For the pencil to show up within your controller, you may need to set the render_mode value on Fuel_page to 'cms' like so (I'm using the page contact which would have a form):
    $page_init = array('location' => 'contact', 'render_mode' => 'cms'); $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init); $this->fuel_page->add_variables($vars); $this->fuel_page->render();

    With regards to validator, you would need to create a new validator object that combines them like you suggested. get_validation() returns by reference as an FYI.
  • edited 6:16PM
    Ah merci, I missed that option, works like a charm!

    Ok, I'm gonna try to merge the validation together, see how that works out.
    Thanks for the answers!
  • edited 6:16PM
    So just for reference, here's what I did.
    Create a validator for your custom fields. Add the rules and let it validate. Then validate the module with a module->save(), and catch the errors in you own validator:

    $this->load->library('validator'); $this->validator->add_rule('some_field', 'required', 'Some_field is required!'); $this->validator->validate(); $this->some_model->save($_POST); $this->validator->catch_errors($this->some_model->get_errors()); $this->form_builder->set_validator($this->validator);

    The form shows all errors and adds a error_highlight class to your custom fields if they didn't validate, all good!
Sign In or Register to comment.