How to get the current url, so that I can redirect?

Support MB Frontend Submission How to get the current url, so that I can redirect?Resolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #48651
    EddyPiVEddyPiV
    Participant

    I want to redirect to the current url (including query strings), so that the changed values become visible right away. Instead of the message that fields were saved successfully, and the query variable '&rwmb-form-submitted=....' added.
    But I'm struggling to get the current url.

    Can you help me?

    #48655
    EddyPiVEddyPiV
    Participant

    Hi, I've taken another route.
    When the user visits a specific page, I store the page URL in a custom field for that user, and I add there the query parameters to the URL, so that it's complete. (The page is only available to logged in users)
    This works, the URL that's stored in the user profile is correct: when I copy it and paste it in the browser it shows the page correctly filled with the data from the query variables.

    That customer field is in the redirect, but it leads to an 'Invalid request. Please try again.' error.
    So the URL is correct, but it looks like the redirect doesn't handle it properly.

    This is the command:
    [mb_frontend_form id='paying-member-input-details' object_id='{{ post.ID }}' post_fields='' submit_button='Save' redirect='{{ user.tg_chat_redirect }}' ]

    Pls advise.

    #48656
    PeterPeter
    Moderator

    Hello Eddy,

    You can use the PHP code to get the current URL and pass it to the frontend form shortcode. Refer to this topic https://wordpress.stackexchange.com/questions/274569/how-to-get-url-of-current-page-displayed

    #48659
    EddyPiVEddyPiV
    Participant

    Thanks Peter.

    But then still, I get the error message 'Invalid request. Please try again' It's caused by the Redirect option. The URL I specify there is correct, pasting it to the url bar of the prowser shows the page correctly, but the redirect doesn't.

    How to have the redirect working properly?

    #48664
    PeterPeter
    Moderator

    Hello,

    If you use the View editor to create the template, you can try this example code

    {% set current_page_id = mb.get_the_ID() %}
    
    [mb_frontend_form post_fields='title,content' ajax="true" redirect="{{ mb.get_permalink( current_page_id ) }}"]

    it works correctly on my site to redirect the current page after submitting the frontend form.

    #48668
    EddyPiVEddyPiV
    Participant

    Thanks Peter, it's working now.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.