APIs on form variables and data structure

Filter: ipt_fsqm_filter_valid_elements

Filter is used to extend form elements which can be used by the form builder. All valid elements are categorized into four sections:

  • Design Elements: Elements that controls the appearance of the form and has nothing to do with actual HTML form elements.
  • MCQ Elements: Quiz elements, where scores can be set.
  • Feedback Elements: Elements for collecting user inputs, mostly in the form of raw text.
  • Other Elements: Anything else which could not be a part of the above. These elements also do not appear in the report and analysis.

The filter provides the only to add a custom element to any of the four sections.

Filter Uses

The filter accepts two arguments. First one is an associative array of valid elements that eForm accepts. Second is the form ID for which it is being called.

/**
 * Filters ipt_fsqm_filter_valid_elements
 *
 * @param      array  $elements  An associative array of all valid elements
 */
function extend_elements_for_currency( $elements ) {
	// Add our definition of new element
	// Since we would be collecting currency
	// so it makes sense to have it inside feedback/freetype elements
	// currency becomes the 'type' of the new element
	$elements['freetype']['elements']['currency'] = array(
		'm_type' => 'freetype', // Required
		'type' => 'currency', // Required and should match with the defined element type
		'title' => __( 'Currency Picker', 'domain' ), // Title of the element
		'description' => __( 'User can input currency amount', 'domain' ), // A short description
		'callback' => 'my_valid_callback', // A valid callback that would handle calls from IPT_FSQM_Form_Elements_Admin/Data/Front classes
		'callback_report' => 'my_valid_callback_report', // A valid callback that would handle calls from IPT_FSQM_Form_Elements_Utilities class
		'callback_report_calculator' => 'my_valid_callback_report_calc', // A valid callback that would handle calls from ajax function
	);

	// To add to MCQ elements
	$elements['mcq']['elements']['my_elem'] = array(
		'm_type' => 'mcq',
		'type' => 'my_elem',
		'title' => '',
		'description' => '',
		'callback' => '',
		'callback_report' => '',
		'callback_report_calculator' => '',
	);

	// To add to Other elements
	$elements['pinfo']['elements']['my_elem2'] = array(
		'm_type' => 'pinfo',
		'type' => 'my_elem2',
		'title' => '',
		'description' => '',
		'callback' => '',
		'callback_report' => '',
		'callback_report_calculator' => '',
	);

	return $elements;
}
add_filter( 'ipt_fsqm_filter_valid_elements', 'extend_elements_for_currency', 10, 1 );

Examples

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Filter: ipt_fsqm_form_element_structure

This filter extends the structural data of an element. With this, you can define the settings structure of a new element.

Filter Uses

Filter accepts three parameters. The first is the associative array that defines the structure of the element. Second is a string that defines the type of the element (which you can extend using the ipt_fsqm_filter_valid_elements filter). Third is the form id for which it has been called.

/**
 * Filters ipt_fsqm_form_element_structure
 * For adding our custom form element
 *
 * @param      array   $structure  An associative array of default structure
 * @param      string  $element    Type of the element for which we need the structure
 * @param      int     $form_id    The ID of the form for which it has been called
 *
 * @return     array
 */
function extended_element_currency_structure( $structure, $element, $form_id ) {
	// Check if being called for our element
	if ( $element != 'currency' ) {
		// Just return the actual structure
		return $structure;
	}

	// Lets define our elements
	$structure = array(
		'type' => $element, // Required
		'm_type' => 'freetype', // Required
		'title' => '', // Default element title for frontend
		'validation' => array(
			'required' => false, // Validation array
		),
		'subtitle' => '', // Default element subtitle for frontend
		'description' => '', // Default element description for frontend
		'settings'   => array(
			'icon' => 0xf155, // To be used with fonticonpicker
			'max' => '',
			'min' => '',
			'step' => '',
		),
		'conditional' => array( // Conditional logic
			'active' => false, // True to use conditional logic, false to ignore
			'status' => false, // Initial status -> True for shown, false for hidden
			'change' => true, // Change to status -> True for shown, false for hide
			'logic' => array( // element dependent logics
				// This will get populated automatically
			),
		),
	);

	return $structure;
}
add_filter( 'ipt_fsqm_form_element_structure', 'extended_element_currency_structure', 10, 3 );

Examples

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Filter: ipt_fsqm_filter_form_data_structure

This filter extends the submission data structure of an element. With this you can define how the submission data of the element could be expected.

Filter Uses

This filter accepts three arguments. First one is the default data structure that is about to get returned. Second is the type of the element. Third is the form ID for which the call was made.

/**
 * Filters ipt_fsqm_filter_form_data_structure
 * For adding our custom form element
 *
 * @param      array   $structure  An associative array of default structure
 * @param      string  $element    Type of the element for which we need the structure
 * @param      int     $form_id    The ID of the form for which it has been called
 *
 * @return     array
 */
function extended_element_currency_data_structure( $structure, $element, $form_id ) {
	// Check if being called for our element
	if ( $element != 'currency' ) {
		// Just return the actual structure
		return $structure;
	}

	// Lets define ours
	$structure['m_type'] = 'freetype'; // Required
	$structure['value'] = ''; // The variable where user input would be stored. The HTML form should also be formatted in the same way
	return $structure;
}
add_filter( 'ipt_fsqm_filter_form_data_structure', 'extended_element_currency_data_structure', 10, 3 );

Examples

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Filter: ipt_fsqm_filter_default_settings

This filter is used to extend the settings variables of a form.

Filter Uses

Accepts two parameters. First is an associative array of all settings variables. Second is the form ID for which it has been called.

/**
 * Filters ipt_fsqm_filter_default_settings
 * to customize the settings
 *
 * @param      array  $settings  The associative array of settings variable
 * @param      int    $form_id   The form ID for which the filter has been called
 *
 * @return     array
 */
function extend_fsqm_form_settings( $settings, $form_id ) {
	// Add our own variable to the array
	$settings['custom'] = array(
		'foo' => 'bar',
	);
	return $settings;
}
add_filter( 'ipt_fsqm_filter_default_settings', 'extend_fsqm_form_settings', 10, 2 );

Examples

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Filter: ipt_fsqm_filter_available_themes

Used to extend themes available for eForm Form Builder.

Filter Uses

Accepts only one parameter. An associative array with a specific structure that defines themes. Each theme can have its own CSS and JS enqueued which needs to be defined from here.

/**
 * Extends available themes for eForm Forms
 * It filters ipt_fsqm_filter_available_themes
 *
 * @param      array  $themes  An associative array of predefined themes
 *
 * @return     array
 */
function extend_fsqm_themes( $themes ) {
	// Add our custom themes
	// Into its own section
	$themes['modern'] = array(
		'label' => __( 'Modern Theme Set', 'domain' ), // Label of the theme set
		'themes' => array( // Theme variable
			'modern-1' => array( // A theme
				'label' => 'Modern Theme - Type 1',
				'src' => array( // CSS files to enqueue
					'common' => array(
						plugins_url( '/css/modern-1/1.10/jquery-ui-1.10.3.custom.css', __FILE__ ),
						plugins_url( '/css/modern-1/form.css', __FILE__ ),
						plugins_url( '/css/modern-tab-pb.css', __FILE__ ),
					),
					'1.9' => array(
						// Optional URLs for supporting jQuery UI version 1.9
					),
					'1.10' => array(
						// Optional URLs for supporting jQuery UI version 1.10+
					),
				),
				'js' => array( // JS Files to enqueue
					'fsqm_modern_form' => plugins_url( '/js/jquery.ipt-fsqm-modern-forms.js', __FILE__ ),
				),
				'colors' => array( '5e7151', 'ffffff', '4e6046' ), // Accent color blocks
			),
			'modern-2' => array( // A theme
				'label' => 'Modern Theme - Type 2',
				'src' => array( // CSS files to enqueue
					'common' => array(
						plugins_url( '/css/modern-2/1.10/jquery-ui-1.10.3.custom.css', __FILE__ ),
						plugins_url( '/css/modern-2/form.css', __FILE__ ),
						plugins_url( '/css/modern-tab-pb.css', __FILE__ ),
					),
					'1.9' => array(
						// Optional URLs for supporting jQuery UI version 1.9
					),
					'1.10' => array(
						// Optional URLs for supporting jQuery UI version 1.10+
					),
				),
				'js' => array(
					'fsqm_modern_form' => plugins_url( '/js/jquery.ipt-fsqm-modern-forms.js', __FILE__ ),
				),
				'colors' => array( '5e7151', 'ffffff', '4e6046' ), // Accent color blocks
			),
		),
	);

	return $themes;
}
add_action( 'ipt_fsqm_filter_available_themes', 'extend_fsqm_themes', 10, 1 );

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Filter: ipt_fsqm_filter_available_webfonts

Used to extend webfonts available for eForm Form Builder.

Filter Uses

Accepts one argument, an associative array of available webfonts. All webfonts have to be from Google Web Fonts directory. We just need to define the base font. The bold and bold italic versions are included automatically.

/**
 * Extends available webfonts for FSQM
 * by filtering ipt_fsqm_filter_available_webfonts
 *
 * @param      array  $fonts  An associative array of fonts
 *
 * @return     array
 */
function fsqm_extend_webfonts( $fonts ) {
	// Add our fonts
	$fonts['ralwway'] = array(
		'label' => "'Raleway', sans-serif", // The label of the font that has to be applied with font-family CSS property
		'include' => 'Raleway', // The URL parameter that has to be appended after https://fonts.googleapis.com/css?family=
	);

	// Add some more
	$fonts['architects_daughter'] = array(
		'label' => "'Architects Daughter', cursive",
		'include' => 'Architects+Daughter',
	);

	return $fonts;
}
add_action( 'ipt_fsqm_filter_available_webfonts', 'fsqm_extend_webfonts', 10, 1 );

Source

Located in classes/class-ipt-fsqm-form-elements-base.php.

Swashata has written 247 articles

Hi there, I am the Lead Developer at WPQuark.com. I love to create something beautiful for WordPress and here I write about how to use them. When I am not working, usually I am doing a number of other creative things ;).