Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active November 30, 2022 22:58
Show Gist options
  • Save mishterk/cef4bcb5ca87f63ff1cc740aea7656a5 to your computer and use it in GitHub Desktop.
Save mishterk/cef4bcb5ca87f63ff1cc740aea7656a5 to your computer and use it in GitHub Desktop.
Testing multiple calculated fields in Advanced Forms Pro for ACF. These resources are for the video: https://www.loom.com/share/fcf6179162374c599b61eb6a1040eb02
[
{
"key": "group_63799935b6476",
"title": "Calculated Fields",
"fields": [
{
"key": "field_637999367d114",
"label": "Number 1",
"name": "number_1",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0,
"default_value": "",
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_6379994b7d115",
"label": "Number 2",
"name": "number_2",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0,
"default_value": "",
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_637999537d118",
"label": "Calculated 1 (Number 1 + Number 2)",
"name": "calculated_1",
"aria-label": "",
"type": "calculated",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0
},
{
"key": "field_6379994d7d116",
"label": "Number 3",
"name": "number_3",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0,
"default_value": "",
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_6379994f7d117",
"label": "Number 4",
"name": "number_4",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0,
"default_value": "",
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_637999af7d119",
"label": "Calculated 2 (Number 3 + Number 4)",
"name": "calculated_2",
"aria-label": "",
"type": "calculated",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0
},
{
"key": "field_63799b410664a",
"label": "Calculated 3 (Display all fields)",
"name": "calculated_3",
"aria-label": "",
"type": "calculated",
"instructions": "This just displays field values and is defined in the <a href=\"http:\/\/advanced-forms-release-testing.test\/wp\/wp-admin\/post.php?post=124&action=edit\">form's \"calculated\" settings<\/a>.",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"hide_admin": 0
}
],
"location": [
[
{
"param": "af_form",
"operator": "==",
"value": "form_6379991d9a109"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"show_in_rest": 0
}
]
<?php
add_filter( 'af/field/calculate_value/name=calculated_1', function () {
return (int) af_get_field( 'number_1' ) + (int) af_get_field( 'number_2' );
}, 10, 0 );
add_filter( 'af/field/calculate_value/name=calculated_2', function () {
return (int) af_get_field( 'number_3' ) + (int) af_get_field( 'number_4' );
}, 10, 0 );
{
"key": "form_6379991d9a109",
"title": "Calculated Fields",
"display": {
"description": "",
"success_message": "<p>Done.<\/p>\n<p>{all_fields}<\/p>\n"
},
"create_entries": false,
"restrictions": {
"entries": false,
"user": false,
"schedule": false,
"edit_own_posts": false
},
"emails": false,
"editing": {
"user": false,
"post": false,
"term": false
},
"slack": false,
"mailchimp": false,
"zapier": false,
"recaptcha": false,
"calculated": {
"field_637999537d118": "",
"field_637999af7d119": "",
"field_63799b410664a": "<p>Number 1: {field:number_1}<\/p>\n<p>Number 2: {field:number_2}<\/p>\n<p>Number 3: {field:number_3}<\/p>\n<p>Number 4: {field:number_4}<\/p>\n"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment