Passing query string which contains an apostrophe [RESOLVED]

I have a form which, on submission, redirects the user to another page. The form has a query string which I pass, through the option under the Confirmations tab, so I can display the information on the next page, like so:

button_link={button_link:17}&page_title={page_title:18}&resource_type={resource_type:19}

This works perfectly, as long as the page title has no punctuation. However, If the page title has an apostrophe, as it sometimes will, it doesn’t pass anything beyond the apostrophe.

How do I escape that in the data which is passed to the next page? I tried writing it as {page_title:18:url} but that made no difference.

Have those merge tags been entered into the query string setting? Merge tags processed in that setting automatically have their values url encoded.


It’s entered exactly like this but on the redirect url, is:

http://kadence-bio.local/thank-you/?button_link=masterclass&page_title=can&resource_type=masterclass

When the actual page title was Can’t Stop Won’t Stop (This is all dummy test data running locally at this point, but the issue is also present in production).

The button_link and source_type data will never contain punctuation, but the page_title will from time to time.

Is the full value present when you check the entry detail page for the submission?

No, it’s truncated there too.
image

What type of field are you using for page_title, and how is the value populated?

It’s pulling the actual title of the page via the following line in the page template:

$page_title = esc_html( get_the_title() );

I didn’t properly explain that the variable defined above is inserted into the form via the shortcode used to load the form onto the page.

echo do_shortcode(‘[gravityform title=false id="’ . esc_attr($gravity_form) . ‘" field_values="button_link=’ . esc_attr($button_link) . ‘&page_title=’ . esc_html($page_title) . ‘&resource_type=’ . esc_attr($resource_type) . ‘"]’);

You need to use urlencode() instead of esc_attr() for the values you are assigning to the field_values query string.

That fixed it. Thanks so much!