Customizing Validation and Other Logic

How do I make a field required? Optional?

To make a field required, add or update a field to include the rule “required” with value “true”, as in the example below. If you wish to make an already-required field optional, you can either remove the validation or set the value to “false”. If creating a new field, remember to add the new field to the relevant forms in order to utilize it.

{
  "label": "My Required Field",
  "name": "myRequiredField",
  "schemaAttribute": "optIn.status",
  "type": "text",
  "validation": [
    {
      "message": "This field is required",
      "rule": "required",
      "value": true
    }
  ]

How do I add Captcha to my forms?

To add Captcha to a form, you need to make changes in your Flow, your form markup, and your JavaScript settings.

  1. In your Flow, make a GET call to the /config/{app}/flows/{flow}/forms/{form} endpoint to verify you will be modifying the correct form. Once verified, add the “captcha” feature to your form and make a PUT request to the same endpoint:
{
  "features": [
      "name":
      "captcha" 
              ], 
  "fields":   [
     ...      ] 
}
  1. In your form markup, add the {* captcha *} JTL tag to your form:
<div style="display:none;" id="traditionalRegistration">
  {* #registrationForm *}
      <!-- ... -->
      {* captcha *}
      <!-- ... -->
  {* /registrationForm *}
</div>
  1. In your JavaScript settings, add the recaptchaVersion setting to specify the version of Captcha to render:
janrain.settings.capture.recaptchaVersion = 2;// 1 or 2

How do I enforce age restrictions/gating?

The birthdate field in the standard flow already supports age-gating and defaults to a minimum age of 16; simply include it on your forms where needed. What follows are instructions on how to modify this field or add additional age-gated fields.

To enforce age restrictions, you can add or update a dateselect field such that it has a validation object with the minYears (and also required) rules. Then, you can add this field to the traditionalRegistration and ssocialRegistration screens (the registrationForm and socialRegistrationForm forms in your Flow, respectively). Below is an example birthday field that only allows users 18 or older to register. Remember to add the new field to the relevant forms in order to utilize it.

{
  "label": "Birthday",
  "name": "birthday",
  "schemaAttribute": "birthday",
  "type": "dateselect",
  "validation": [
    {
      "rule": "required",
      "value": "true",
      "message": "Birthdate is required"
    },
    {
      "rule": "minYears",
      "value": 18,
      "message": "You must be at least 18 years old to register"
    }
  ]
}
Note. If you wish to implement site-specific (API client specific) age-gating, this is supported; however, age-gating is not configurable via the Configuration API. Please contact your Janrain representative for more information.