How to hide fields in a custom module's form?

edited March 2012 in Modules
How do I go about hiding certain fields from a module's input form? I have 3 fields that get populated automatically that should never be entered manually via a form, so I need those fields to not be editable in Fuel, and thus be absent from the edit/create form for the module.

Thanks,
Erik

Comments

  • edited 5:50PM
    Two ways:

    In the head of your model:

    public $hidden_fields = array('field_name');

    or in the form_fields method

    $fields['field_name']['type'] = 'hidden';
  • edited 5:50PM
    Great, thanks!

    A related question I just thought of is rather than making the form fields not appear at all, is there a way to have the values of the hidden fields show up as plain text on the screen so that the values cannot be altered, but still visible?

    Also, is there a way to make the Create form different than the Edit form? The example here would be to now show the hidden fields at all on the Create form, but for the values to display as plain text on the edit/view form.

    Thanks
  • edited March 2012
    Sure is:

    $fields['field_name']['displayonly'] = true;

    For a complete list of what your fields can have check out the Form_builder::_normalize_value() method.

    You could create different forms but it would be a PITA. You'd be better served by evaluating the $values['id'] in your modules form_fields() method. If there's an id value = edit else it's a create.
Sign In or Register to comment.