Adding a Field to Another Module's Form

Applies to: Jamroom 7.0+ Last verified: 2026-10-24
  • Without code

    To add a field for your own site, use the Form Designer: no module needed. See Using the Form Designer.

    Use a module when the field belongs to your module's feature, and should appear only while your module is active. The Timeline module does this: its Add to Timeline checkbox appears on other modules' create forms.

  • Listening for form_display

    Every form fires the form_display event before it's shown. Listen for it in _init():

    jrCore_register_event_listener('jrCore', 'form_display', 'xxFoo_form_display_listener');
  • And add your field when the form is the one you want:

    function xxFoo_form_display_listener($_data, $_user, $_conf, $_args, $event)
    {
        if (isset($_data['form_view']) && $_data['form_view'] == 'jrProfile/settings') {
            $_tmp = array(
                'name'     => 'profile_color',
                'label'    => 'Profile Color',
                'help'     => 'A hex color code for the background of your profile',
                'type'     => 'text',
                'validate' => 'printable',
                'required' => false
            );
            jrCore_form_field_create($_tmp);
        }
        return $_data;
    }
  • form_view is (module)/(view) of the form, such as jrProfile/settings or jrAudio/create. Check it, so the field only goes on that form.

  • Naming the field

    The field is saved with the item, like the form's own fields. Use the form's prefix, such as profile_ on the profile settings form: a field without it isn't saved to that item. The value is then {$profile_color} in profile templates, and can be used in {jrCore_list} like any key.

    To find a form's view name, write $_data to the Debug Log with fdebug($_data) and open the form. See Reading the Debug Log.

Tags