PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Use relative path when redirect

  1. finddarkpoet
    Member

    I'm using redirect method for confirmation with query strings. Since I didn't want the "?" in the url, I use an absolute url like this:

    http://www.domain.com/{department:1:value}.html

    It works nicely. But now i'm have multiple languages for my site, so the url for different languages will change to http://www.domain.com/zh-hans/{department:1:value}.html or http://www.domain.com/es/{department:1:value}.html. In this case, I need to use a relative url.

    When I only use {department:1:value}.html in the redirect box, the result will add a ":/" before it. Then the link will become http://www.domain.com/:/actual-value.html.

    How do I get rid of the ":/" ? or is there another work-around?

    Posted 12 years ago on Sunday July 1, 2012 | Permalink
  2. David Peralty

    Gravity Forms can't do relative redirects, and I am not certain how you can easily grab/use the multi-language code as part of the redirect. What plugin are you using for your translations?

    Posted 12 years ago on Monday July 2, 2012 | Permalink
  3. finddarkpoet
    Member

    Hi David, I'm using WPML for translations.

    Any workaround?

    Thanks!

    Posted 12 years ago on Monday July 2, 2012 | Permalink
  4. You have a unique situation which might require a unique solution. You could handle the redirect in your theme's functions.php. You can rewrite the redirect URL based on whether you need a relative or absolute URL. You would use the gform_confirmation filter:

    http://www.gravityhelp.com/documentation/page/Gform_confirmation

    The logic and code to determine the URL is up to you. But then use the gform_confirmation filter to set that URL.

    That is one approach.

    The other approach would be to send something in the query string, then have a template hold the logic for your redirect. I like the first option better, but we can explore this option as well if you like.

    Posted 12 years ago on Monday July 2, 2012 | Permalink
  5. finddarkpoet
    Member

    Hi Chris,

    Thanks for the tips. The first option sounds great. I'm not really a code person, can you shed some light on how to use the filter.

    Posted 12 years ago on Tuesday July 3, 2012 | Permalink
  6. Sure. Can you give me some example data to go with, and some rules. Rules which mimic your admin routing. Something like

    If the choice is "whatever" then send the email to "this address"
    AND
    include this information in the notification to the user.

    If we start with that I should be able to point you in the right direction.

    Posted 12 years ago on Tuesday July 3, 2012 | Permalink
  7. finddarkpoet
    Member

    Sorry for the late reply.

    The idea is to use the form to perform a simple search function.

    For example, I have already created pages and the permalinks are like this:

    domain.com/chest-pain-clinic-doctors.html
    domain.com/general-cardiology-doctors.html

    So, in the form, I have created a dropdown field, admin label is "department", with choices like "Chest pain clinic doctors", and set value as "chest-pain-clinic-doctors", in the confirmation setting, I set the redirection to:
    http://domain.com/{department:1:value}.html
    when it's selected and click on the submit button, the page redirects to domain.com/chest-pain-clinic-doctors.html, it works perfectly.

    My problem is, I have the same pages for multiple languages, take Spanish for example, the aforementioned urls will become:

    domain.com/es/chest-pain-clinic-doctors.html
    domain.com/es/general-cardiology-doctors.html

    For Chinese, they will become:

    domain.com/zh-hans/chest-pain-clinic-doctors.html
    domain.com/zh-hans/general-cardiology-doctors.html

    So of course, absolute url like this http://domain.com/{department:1:value}.html won't work.

    Is this information enough?

    Best regards,

    Posted 12 years ago on Friday July 13, 2012 | Permalink
  8. Is the language portion of the url (slug) available in the page you're on? Could you store it in a hidden field on the form ("language") and then use that in your confirmation redirect? So you might have a hidden "language" field and it would be pre-populated with "zh-hans" in the case of Chinese?

    Posted 12 years ago on Friday July 13, 2012 | Permalink
  9. finddarkpoet
    Member

    First of all, I'm using the very same form for all languages, translated with WPML. Let's say my form is on home page, it will be:

    English:
    domain.com
    Spanish:
    domain.com/es/
    Chinese:
    domain.com/zh-hans/

    Which means the language slug is already included in the url.

    Since I'm using the same form for all languages, the form can not determine what language currently it's using. And I can only set one confirmation redirect.

    Posted 12 years ago on Friday July 13, 2012 | Permalink
  10. David Peralty

    You are using the same form, but they show up on different URLs, so what if using our gform_pre_render hook, you grabbed the current URL, parsed out the "folder" if it exists, and use that to build your redirect URL?

    So on load, check current URL, explode by "/" grab the last part, put that value in a hidden field, and then use that value to make your redirect?

    Posted 12 years ago on Friday July 13, 2012 | Permalink
  11. Relative redirects would be very nice. My situation is not as unique. I develop websites on a development server (with a different domain than the final location). If I hard code the domain, I have to remember to change each redirect location every time I push a code update to the live server. It would be MUCH easier if I was allowed to enter '/redirect-location' instead of 'http://example.com/redirect-location'.

    Please consider adding this feature.

    Posted 11 years ago on Tuesday August 14, 2012 | Permalink