• Resolved jamminjames

    (@jamminjames)


    We would like to send the form submitter to url after submission, but the url includes an ampersand for a query delimiter, and that is getting changed to “&” which prevents the link form working. How can this be fixed?

    The url is actually provided in a hidden field. Then, in the form behavior, we are using “Redirect user to a URL” and the Redirect URL field has this in it:

    {hidden-4}&promo=SponsorCode

    I’ve tried substituting the ampersand code ‘%26’ in the above, but that gets ignored and dropped entirely. Do I need to intercept the form via a Forminator API function and fix it there? If so, can you suggest a function? I’m not sure what hook could be used to intercept before the user gets redirected.

    Thanks for any help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @jamminjames

    I hope you are doing well today.

    It seems in previous case we were able to provide some solutions to support ampersand in a hidden field. I pinged our SLS Team to review this new query and see how complex this will be. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter jamminjames

    (@jamminjames)

    I think we might be able to hook in using the forminator_custom_form_submit_before_set_fields hook, correct? However, how would we test the result? How can we see what happens before the user is sent to the url?

    • This reply was modified 10 months, 2 weeks ago by jamminjames.
    • This reply was modified 10 months, 2 weeks ago by jamminjames.
    Thread Starter jamminjames

    (@jamminjames)

    I have not had much luck with the forminator_custom_form_submit_before_set_fields action. Everything I try results in a form submission error. I’ve tried things like this:

    function my_submit_before_set_fields( $entry, $form_id, $form_data_array ) {
    if ($form_id == 38164) {
    $instanturl = str_replace('&', '&', $form_data_array['hidden-1']['value']);
    $form_data_array = array_replace($form_data_array, $instanturl);
    }
    }
    add_action('forminator_custom_form_submit_before_set_fields', 'my_submit_before_set_fields', 10, 3);

    By the way, since the “behavior” provided is “Redirect user to a URL”, it seems like this sort of thing should be built in as a filter… before redirecting, Forminator ought to make sure any such introduced mistakes like “&” are replaced with the proper characters.

    • This reply was modified 10 months, 2 weeks ago by jamminjames.
    • This reply was modified 10 months, 2 weeks ago by jamminjames.
    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jamminjames,

    This snippet should have worked in your use case:

    <?php
    
    add_filter( 'forminator_form_submit_response', 'wpmudev_fix_response_url_redirect', 20, 2 );
    add_filter( 'forminator_form_ajax_submit_response', 'wpmudev_fix_response_url_redirect', 20, 2 );
    function wpmudev_fix_response_url_redirect( $response, $form_id ) {
    	if ( $form_id != 6 ) {
    		return $response;
    	}
    
    	if ( ! empty( $response['url'] ) ) {
            $response['url'] = urldecode($response['url']);
            $response['url'] = str_replace('&amp;', '&', $response['url']);
    	}
    
    	return $response;
    }

    Could you please confirm by adding the above code as a mu-plugins and see whether it works?

    You’ll need to update the following line with your form ID, suppose the form ID is 123, then the following line will change from:
    if ( $form_id != 6 ) {

    To:
    if ( $form_id != 123 ) {

    Please do let us know how that goes.

    Kind Regards,

    Nithin

    Thread Starter jamminjames

    (@jamminjames)

    That works, thank you very much. Just for future reference, how could I see the result of $response or echo other things within the function for testing purposes?

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jamminjames,

    You can use the error_log in your code to display the value of the variables, for example, add this line before returning the $response :

    error_log('Response: ' . print_r($response, true));

    Please do note that you’ll need to have debug mode enabled and these values will be logged in the debug.log file.

    Please check the following doc for more info:
    https://developer.www.ads-software.com/advanced-administration/debug/debug-wordpress/#custom-php-debugging

    Best Regards,

    Nithin

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sending to url in form behavior, problem with ampersand’ is closed to new replies.