This filter fires on the Form Editor page when a field button is clicked or dragged on to the form, it can be used to prevent a field being added to the form if the conditions you define are not met.


gform.addFilter('gform_form_editor_can_field_be_added', function (canFieldBeAdded, type) {
    // return false to prevent a field being added.
    return canFieldBeAdded;


  • canFieldBeAdded boolean

    Defaults to true.

  • type string

    The current field type.

This example uses the gform_admin_pre_render filter to load the hook on the form editor page.

add_filter( 'gform_admin_pre_render', function ( $form ) {
	echo GFCommon::is_form_editor() ? "
		<script type='text/javascript'>
		gform.addFilter('gform_form_editor_can_field_be_added', function (canFieldBeAdded, type) {
			if (type == 'coupon') {
				if (GetFieldsByType(['product']).length <= 0) {
					alert('" . __( 'You must add a Product field to the form first', 'gravityformscoupons' ) . "');
					return false;
				} else if (GetFieldsByType(&#91;'coupon'&#93;).length) {
					alert('" . __( 'Only one Coupon field can be added to the form', 'gravityformscoupons' ) . "');
					return false;
			return canFieldBeAdded;
		</script>" : '';

	//return the form object from the php hook
	return $form;
} );

##Source Code

This filter is located in js.php