How to request custom donation fields on a donation page

This HOWTO assumes you understand the complexity of using custom fields and have already created custom donation fields

Custom donation fields are requested automatically on new donation pages. This HOWTO provides the code that requests all custom donation fields and describes ways to limit the custom donation fields requested.

Only donation pages can request custom donation fields. No other page type can request or display custom donation fields.

It is possible to limit the number of custom donation fields requested on a donation page. First, you will need to remove the code that requests all custom donation fields. Then, you can either insert requests for individual fields or for types of fields.

Liquid included in all donation pages

By default, donation pages automatically request all custom donation fields. If you want to replace this code, you will first need to find and remove it from the page template.

Show code included on donation pages to request all custom donation fields.

The above code to request all custom donation fields appears directly below the code that adds employer fields to the donation page. Whether employer fields are displayed is determined by the settings in the payment processor attached to the donation page.


Liquid to display individual custom donation fields

The Liquid code needed for each custom donation field type is listed here:
Field type Liquid code
text {% text_field "custom_values.slug" %}
number {% text_field "custom_values.slug" %}
check box {% check_box "custom_values.slug" %}
multiple choice {% collection_select "custom_values.slug", custom_fields.donation.slug.multiple_choice_options %}

To make a text or number field required, you can add the HTML5 required attribute, as follows:
{% text_field "custom_values.slug", required: "required" %}


Request only one type of custom donation field

It is possible to request only custom donation text fields.

Show code to request only text fields.

It is possible to request only custom donation number fields.

Show code to request only number fields.

It is possible to request only custom donation multiple choice fields, which includes yes/no fields.

Show code to request multiple choice fields.

It is possible to request only custom donation true / false fields.

Show code to request only true / false fields.


Limiting the number of custom donation fields requested

Using the liquid limit and offset filters, you can easily control how many fields of a certain time are called to the page the code is placed on. Add the phrase "limit:#" and "offset:#" to the 'forloop' you're using to call the custom fields.

Limit the number of custom donation fields requested using the limit filter. The order of the fields requested is determined by the order they are listed in Settings > Defaults > Custom fields > Donations. You can skip fields and not request them by using the offsetting filter. The request begins at a different point than the first listed field (e.g. offset:1 begins requesting fields after skipping 1 field, offset:2 would skip 2 fields, etc).

Request the first 2 custom donation fields.

Show code to request only the first 2 custom donation fields.

Request the first 3 multiple choice custom donation fields

Show code to request only the first 3 multiple choice custom donation fields.


Limiting the custom donation fields requested based on field slug

You can use a conditional "if" statement to check if the slug of the custom field contains a specific word:

Request multiple choice custom donation fields with the word "lobbyist" in the slug:

Show code to request multiple choice fields with "lobbyist" in slug.

Request text or number custom donation fields with the word "raffle" in the slug:

Show code to request fields with "raffle" in slug.


How to create custom donation fields

Introduction to custom fields

How to create custom people fields

How to request custom people fields on webpages

Liquid variables available in email

If you’re unclear on how this feature works, please ask a question. If you would like to see changes to this feature, please submit a suggestion.