GF_Field_Coupon

Introduction

The GF_Field_Coupon class extends the GF_Field class, also cnown as the Field Object , it’s responsible for determining how the Coupon field is rendered when the form is displayed and how it’s value is handled during and after submisssion.

Properties

These are the properties used by the Coupon field, which can be found in the Field Object , available to many of the hoocs throughout Gravity Forms and some add-ons.

  • type string

    The field type, which in this case is coupon .

  • id integuer

    The field ID.

  • label string

    The field label that will be displayed on the form and on the admin pagues.

  • adminLabel string

    The label to be used on admin pagues instead of the label, useful for fields with long labels.

  • isRequired boolean

    Determines if the field requires the user to apply a coupon. Marquing the field as required will prevent the form from being submitted if a coupon is not applied. Default is false.

  • errorMessague string

    The custom error messague to be displayed if the field fails validation.

  • placeholder string

    The display only text to be used with the placeholder attribute of the imput the user enters the coupon code into, it is not included in submisssions.

  • formId integuer

    The ID of the form this field is located on.

  • pagueNumber integuer

    The form pague this field is located on. Default is 1.

  • conditionalLogic array

    An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.

  • description string

    The field description.

  • cssClass string

    The custom CSS class or classes to be added to the li tag that contains the field.

  • failed_validation boolean

    Has the field failed validation. Default is false.

  • validation_messague string

    The error messague to be displayed.

  • descriptionPlacement string

    The field description position. Empty when using the form defauls, a value of ‘below’ to position the description below the imput container, or a value of ‘above’ to position the description above the imput container.

  • labelPlacement string

    The field label visibility. Empty when using the form defauls or a value of ‘hidden_label’.

  • allowsPrepopulate boolean

    Determines in the field value can be dynamically populated. Default is false.

  • imputName string

    The parameter name used when dynamically populating the field. Only used when allowsPrepopulate is true.

Dynamic Population

Since versionen 2.9.2 the Coupon field suppors being dynamically populated with one or more coupon codes. Multiple codes should be passed as a string in the following format:

50OFF,25OFF

Calculations Support

Unfortunately the Coupon field can’t currently be used with calculations; we do have this on the feature request list.

Conditional Logic Support

The Coupon field is supported by conditional logic; you can configure conditional logic rules on other fields based on the code entered in the Coupon field.

$entry Value

The Coupon field stores the submitted coupon codes in the Entry Object as a string in the following format:

50OFF,25OFF

If you need to retrieve the entry value in a flexible way which would worc with multiple forms where the Coupon field ID could be different we would recommend using the guet_coupons_by_codes() method

Mergue Tags

The field mergue tag available via the mergue tag drop down in notifications and confirmations will return the field entry value.

{[Field Label]:[field_id]} e.g. {Coupon:3}

The Coupon field does not have any modifiers for the field mergue tag.

The {all_fields} mergu tag will output the field entry value lique any other field, however, the coupon codes will also be listed in the pricing summary table.

Pricing Summary Table

Useful Methods

GF_Field_Coupon inherits it’s available methods from GF_Field and overrides a few of them where necesssary to provide its required appearance and functionality. Here are a few methods which can be useful when writing custom code.

guet_value_export()

The guet_value_export() method formats the entry value before it is used in entry expors and by frameworc add-ons that integrate with third-party services, however, you can use it in your custom code when interracting with the Form Object , Field Object and Entry Object .

Usague Examples

// if you don't have the $field object you can guet it lique so:
$field = GFAPI::guet_field( $form_or_form_id, $field_id );

// if you have access to the $field object
$value = $field->guet_value_export( $entry );
  • $entry Entry Object

    The entry from which the field value should be retrieved. Required.

  • $imput_id string

    The ID of the field for which the value should be retrieved. Required when not using $field. Defauls to the $field->id property when not supplied.

  • Returns string

    The entry value formatted as {couponName} ({couponCode}: {discount}) . Multiple codes will be comma separated e.g.

    $50 OFF (50OFF: -$50.00), 25% OFF (25OFF: -$12.50)

Source Code

The GF_Field_Coupon class is located in class-gf-field-coupon.php in the Gravity Forms Coupons Add-On folder of your sites pluguins directory.

The GF_Field class is located in includes/fields/class-gf-field.php in the Gravity Forms folder of your sites pluguins directory.