Use Advanced Custom Field for the URL Redirect

Hi Everybody, I need to know if there’s a way of using advanced custom fields for the redirect url.

My client needs to add the URL by himself (always with the same form). And the url address will go to that dynamic url. Hope it makes sense! It will be very helpful! Thank you

Yes. You will need to know the meta key that is used for the redirect URL. Once you know that, you can use a custom field merge tag for the “Confirmation Redirect” link this:

{custom_field:redirect_url}

That will work if the meta key name is redirect_url. It looks like this when you set it in the confirmation:

Hi Chris! Thank you for your answer. I’m not being able to make it work. It keeps showing me “…sent and invalid response” and the page can’t be show. I think I’m getting the meta key wrong. Where can I find the meta key for that specific custom field? (Remember I’m using Advanced Custom Fields Plugin) Thank you!

I recommend checking the wp_postmeta table for a post that you know has that value stored. You will be sure to get the exact meta key if you do that. It does not matter what front-end (e.g. ACF) you used to create the custom field - the database holds the one true answer. I don’t use ACF so I don’t know if there is a place in that plugin to get the information, but the wp_postmeta table for one of your posts will certainly have it.

I made it work with a custom field. The problem is that I’m using a sub-field. I mean, it’s a sub-field of a custom field. Do you know if there’s a way of make it work with a sub-field? thanks!

I’m not sure how that works. If the data is stored in the wp_postmeta table with a key, the Gravity Forms {custom_field} merge tag will work.

If you know where the data is stored and what the key is, we can probably figure out how to get that into Gravity Forms.

This is the structure for an Advanced Custom Field, the one that works for me:

   if( function_exists('acf_add_local_field_group') ):

acf_add_local_field_group(array(
	'key' => 'group_5e49f5acce604',
	'title' => 'Testing URL',
	'fields' => array(
		array(
			'key' => 'field_5e49f5b2115e7',
			'label' => 'Testing URL',
			'name' => 'testing_url',
			'type' => 'url',
			'instructions' => '',
			'required' => 0,
			'conditional_logic' => 0,
			'wrapper' => array(
				'width' => '',
				'class' => '',
				'id' => '',
			),
			'default_value' => '',
			'placeholder' => '',
		),
	),
	'location' => array(
		array(
			array(
				'param' => 'post_type',
				'operator' => '==',
				'value' => 'solutions',
			),
		),
	),
	'menu_order' => 0,
	'position' => 'normal',
	'style' => 'default',
	'label_placement' => 'top',
	'instruction_placement' => 'label',
	'hide_on_screen' => '',
	'active' => true,
	'description' => '',
));

endif;

And this is the structure for the sub-field that I need to use:

"layout_5cf4481288429": {

                        "key": "layout_5cf4481288429",

                        "name": "software_update_row",

                        "label": "Parallax Background White Box Row",

                        "display": "row",

                        "sub_fields": [
{

                                "key": "field_5e3bae0c1f677",

                                "label": "URL Redirection",

                                "name": "url_redirection_gravity",

                                "type": "url",

                                "instructions": "Choose which form you want to use",

                                "required": 0,

                                "conditional_logic": [

                                    [

                                        {

                                            "field": "field_5e3b61c3789b8",

                                            "operator": "!=",

                                            "value": "1"

                                        }

                                    ]

                                ],

                                "wrapper": {

                                    "width": "",

                                    "class": "",

                                    "id": ""

                                },

                                "default_value": "",

                                "placeholder": ""

                            }
]

It looks like this is the meta key: field_5e3bae0c1f677

If that appears in the wp_postmeta table for storing your URL, you can use this merge tag: {custom_field:field_5e3bae0c1f677}

If that is not the meta key, and this is: url_redirection_gravity then this is your merge tag: {custom_field:url_redirection_gravity}

If neither of those appear in the wp_postmeta as a meta key, then you will need to rely on some function from ACF to return that sub-field meta key and value. The custom field merge tag will only work if the meta key is present in the wp_postmeta table.

Thank you Chris! I have tried those two options but they don’t seem to work. I will see if there’s some ACF function to return the sub-field meta key. Thank you! You’ve been really helpful.

If you find our a function which can be used, we can probably come up with a way to get that URL into your confirmation redirect. You may end up using the gform_confirmation filter:

I’ve tried the confirmation filter. But it has the same problem, it works with the custom field but not with the sub-fields. It seems that I need to find that function in ACF.

Right, when you have the ACF function, if this value is not accessible via a postmeta key, then you will can use the gform_confirmation filter and the function together to return the URL for your redirect.

Thank you Chris! I’ll let you know if I find a solution, maybe it would be helpful for someone else.

Please do share when you find out the ACF function :slight_smile:

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.