The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Returning to previous page when return URL contains an "&"

Labels

This Discussion is public

Notifications

WordPress converts "&" to "&" when the hidden field used to store a return URL is saved.  This results in being redirected to an invalid URL after an entry is updated.  The following code added to your child theme functions.php solves the problem discussed here: https://formidableforms.com/help-desk/using-return-to-previous-page-after-edit-code-has-issues-with/.  As always, make sure you have FTP access to your site before editing functions.php from the WordPress backend in case something goes wrong.

add_filter('frmpro_fields_replace_shortcodes', 'frm_replace_amp_entity_with_amp', 10, 4);
function frm_replace_amp_entity_with_amp($value, $tag, $atts, $field){
 if ( isset($atts['amp']) ) {
 $value = str_replace( "&", "&", $value);
 }
 return $value;
}

In PHP, you should use html_entity_decode($str) to convert the html entities to characters. URLs may have other characters that need to be converted as well. html_entity_decode() will take care of all of them.

You can also capture query parameters and return URLS with jQuery to save a round trip to the server to execute PHP. Assuming the return URL is the URL that sent you to the page, you can capture it from window.location.origin and store it in a hidden field.

If you want to capture individual query string variables and store them in hidden fields, you could use the following jQuery function:

function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}

You would use this function as so:

var entryid = getParameterByName('entry', window.location.href),
parentid = getParameterByName('parentid', window.location.href),
usraction = getParameterByName('reqaction', window.location.href);

Discussion closed.