All Collections
Website
Theming
Form customization
How to request custom people fields on donation pages
How to request custom people fields on donation pages

Donation pages are unique in that they can accept both custom people fields and custom donation fields.

Updated over a week ago

📌 Note: Custom Fields are available as add-ons. For more information on adding new features please see the add-ons page in your nation.

Table of Contents

Donation pages are unique in that they can accept both custom people fields and custom donation fields. This page includes example code snippets for including custom people fields on Donation pages and assumes that you have already created custom people fields. You can also include custom donation fields on Donation pages.

The following code examples should be placed in the Template section of your Donation page, anywhere after the {% form_for donation %} Liquid tag.

The following code will request all custom people fields from your nation on a donation page:

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_text? or custom_field.is_number? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
   
    {% elsif custom_field.is_boolean? %}
    <label class="checkbox" for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{% check_box custom_field_id, class:"checkbox" %} {{ custom_field.name }}</label>
                                                                       
    {% elsif custom_field.is_multiple_choice? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% collection_select custom_field_id, custom_fields.signup[custom_field.slug].multiple_choice_options, class:"select" %}
    {% endif %}
   
  </div>
</div>

{% endfor %}

Liquid to request individual custom people fields

The Liquid code needed for each custom people field type is listed here:

Please note: For checkbox, number, and text fields, the "signup." prefix before "custom_values" is not required on signup pages and should be removed. The signup prefix is required as written on all pages when requesting multiple choice fields.

To make a text or number field required, you can add the HTML5 required attribute, as follows:

{% text_field "signup.custom_values.slug", required: "required" %}

Request only one type of custom people field

It is possible to request only custom people text fields.

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_text? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
    {% endif %}
                                                                       
  </div>
</div>
                                                                       
{% endfor %}

It is possible to request only custom people number fields.

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_number? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
    {% endif %}
                                                                       
  </div>
</div>
                                                                       
{% endfor %}

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

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_multiple_choice? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% collection_select custom_field_id, custom_fields.signup[custom_field.slug].multiple_choice_options, class:"select" %}
    {% endif %}
   
  </div>
</div>

{% endfor %}

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

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_boolean? %}
    <label class="checkbox" for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{% check_box custom_field_id, class:"checkbox" %} {{ custom_field.name }}</label>
    {% endif %}
                                                                       
  </div>
</div>
                                                                       
{% endfor %}

Limiting the number of custom people fields requested

Using the liquid limit and offset filters, you can easily control how many fields of a certain type 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 > People. 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 people fields.

{% for cf in custom_fields.signup limit:2 %}
<!-- limits output to 2 custom fields^^^ -->

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
    {% if custom_field.is_text? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
    {% endif %}
  </div>
</div>
{% endfor %}

Request only the first 4 custom people number fields.

{% for cf in custom_fields.signup limit:4 %}
<!-- limits output to 4 custom fields^^^-->

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

<div class="row-fluid">
  <div class="span12">
   
    {% if custom_field.is_number? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
    {% endif %}
                                                                       
  </div>
</div>
                                                                       
{% endfor %}

Limiting the custom people 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 custom people fields with the word "shirt_size" in the slug:

{% for cf in custom_fields.signup %}

{% assign custom_field = cf[1] %}
{% assign custom_field_id = 'signup.custom_values.' | append: custom_field.slug %}

{% if custom_field.slug contains "shirt_size" %}
<!-- check for slug to contain "shirt_size" -->

<div class="row-fluid">
  <div class="span12">
                                                                       
    {% if custom_field.is_text? %}
    <label for="donation_signup_custom_values_{{ custom_field.slug }}_custom">{{ custom_field.name }}</label>
    {% text_field custom_field_id, class:"text" %}
                                                                       
    {% endif %} <!-- end slug check -->
                                                                       
  </div>
</div>

{% endif %}

{% endfor %}

Related HOWTOs

Did this answer your question?