ninja_forms_register_field

Type: Function
Accepted Parameters:  Slug, Array of arguments. See below.

This function is used to register a new field type. Developers can use this to extend the functionality of Ninja Forms with new fields.

The arguments accepted are:

  • name - string – Required. This is the name that will appear on the add field button.
  • edit_options - array – Optional. An array of settings options that will appear on the edit field screen. Use this if your new field has specific options that need to be set by the admin. Each of these options can contain:
    • type – string – Required. What type of input should this be? Accepted types are: text, textarea, select (see full code example below), checkbox, radio.
    • name – string – Required. The name of the setting. This will be used to retrieve the value later. It should always be a programmatic name, not a label. For instance: (my_name).
    • label – string – Required. Label to be shown before the option.
    • class – string – Optional. Comma separated list of additional classes to be added to the input element.
  • display_function - string – Required. Name of the function that is called when the field is displayed to the user on the front-end.
  • edit_function - string – Optional. Name of the function that is called below the “edit options” in the field edit screen.
  • sub_edit_function – string – Optional. Name of the function that is called on the backend when an admin edits  a user submission. This will replace the normal display_function call when editing submissions.
  • group – string – Optional. Which registered field group does this belong to? This will affect how your field is organized in functions that generate registered field lists.
  • edit_label – true/false – Optional. Show the ‘label’ field in the backend field editor? Default: true.
  • edit_label_pos - true/false – Optional. Show the ‘label position’ field in the backend field editor? Default: true.
  • edit_req -  true/false – Optional. Show the ‘required field’ selector in the backend field editor? Default: true.
  • edit_custom_class - true/false – Optional. Show the ‘custom class’ field in the backend field editor? Default: true.
  • edit_help - true/false – Optional. Show the ‘edit help’ checkbox in the backend field editor? Default: true.
  • sidebar - string – Optional. If you want Ninja Forms to show this field on the ‘Field Settings’ page, which sidebar should it show up in?
  • pre_process - string - Optional. Name of the function to be called during pre-processing.
  • process - string – Optional. Name of the function to be called during processing.
  • post_process - string – Optional. Name of the function to be called during post_processing.
  • req_validation - string – Optional. Name of the function to be called when this field is marked as required. If a function is provided, it will be used in place of the default required validation. This function will be passed the field id and the user value. It should return true if the user value passes and false if the user value is empty.

Example: