• Resolved mightyherrington

    (@mightyherrington)


    I am trying to create a simple autocomplete redirection/search function to redirect the visitor to their selected page.

    Example: I have a custom post type Destinations, and I have created the relevant ACF field (a Page Link type field) that properly populates all my destinations into the search field.

    When a destination is selected and the form is submitted, I would like the visitor to be taken to that specific page.

    I know there is a “target” attribute that I can use, but I’m not sure how I can connect it to the form.

    Any help is much appreciated, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi! This sounds like a perfect use case for Advanced Forms.

    Wordpress has a built-in function for triggering a redirect called wp_redirect (documentation). All you have to do is pass it a URL and it will send your users on their way. I would use the af/form/submission action, retrieve the page URL with af_get_field, and pass it to wp_redirect. Something like this:

    function handle_form_redirect() {
      wp_redirect( af_get_field( 'FIELD_NAME' ) );
      exit;
    }
    add_action( 'af/form/submission/key=FORM_KEY', 'handle_form_redirect' );
    

    Haven’t tested this code but I hope it works!

    Thread Starter mightyherrington

    (@mightyherrington)

    This is very much appreciated, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect to Selected Page on Submit’ is closed to new replies.