Custom Fields ("user" defined)
From version 9.3 ResourceSpace can be configured with custom fields. An example of this feature already being used using this system can be seen on Research Request.
A custom field structure looks like below:
array( "id" => 1, "title" => "~en:Roles~fr:Rôles", "type" => FIELD_TYPE_CHECK_BOX_LIST, "required" => true, "options" => array("IT", "~en:Customer Success~fr:Succès Client", "Sales", "Support", "Admin") )
A field is considered valid as long as it has the following keys/properties:
- id - a numeric and unique number. This is used to easily generate HTML properties such as ID or name.
- title - an i18l string or just a normal string. This is rendered as the label.
- type - the field type. This key is using the ResourceSpace metadata field type constants (e.g FIELD_TYPE_TEXT_BOX_SINGLE_LINE)
- required - true if the field is required, false otherwise
- options - Required key if the type is part of the $FIXED_LIST_FIELD_TYPES. List of options. An option can be an i18l string.
Note: if a field is missing any of the required keys, upon validation - using get_valid_custom_fields(), it will be dropped from the list of fields.
On the page where you want to use custom fields, use the process_custom_fields_submission() at the top of the page. This will prepare default values or return the posted data for each field.
To render the fields just call render_custom_fields() passing the processed custom fields. The custom fields will be rendered based on the type. If the type isn't supported, the field will be displayed as a single line text box.