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

This page includes example code snippets for including custom people fields on Petition pages.

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

This page includes example code snippets for including custom people fields on Petition pages and assumes that you have already created custom people fields.

The following code examples should be placed in the Template section of your Petition page after the {% form_for petition_signature %} Liquid tag.

The following code will request all custom people fields from your nation on a petition 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="petition_signature_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="petition_signature_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="petition_signature_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 %}

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="petition_signature_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="petition_signature_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="petition_signature_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="petition_signature_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="petition_signature_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="petition_signature_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="petition_signature_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?