Forms App and redirection

  • Hi


    I'm using a Collection and the Forms App to create a lead magnet/landing page. On form submission the page redirects to a 'download' page.


    This is the page structure:

    • www.domain.com/unique-slug
    • www.domain.com/unique-slug/downloads


    The problem is the redirect needs to contain a unique slug, because the download will be different for each campaign.


    Within the Forms App I can use an ID in curly braces to populate things like the Email subject line



    But curly braces don't appear to work in the redirection box in the Forms App settings page.



    Is there a way to use an ID to make the redirection dynamic?




    Another thing I've tried is to use the action attribute, like this:


    action="<perch:content id="lm_campaign_name_slug">/downloads"


    This redirects to the correct page (using a unique slug), but the form no longer validates.


    Is there an obvious solution to this I'm just not seeing?



    Health check

    • Perch Runway is up to date
    • PHP 7.1.26 is up to date
    • MySQL 5.7.25 is up to date
    • Image processing available
  • Update...


    I always like to use novalidate on perch:form


    My opening tag looks like this

    Code
    1. <perch:form novalidate id="lead_magnet_form" method="post" action="<perch:content id="lm_campaign_name_slug">/downloads" app="perch_forms" class="form">
    2. // Redirect is dynamic, but Perch validation doesn't work?
    3. // Ideally I'd like to use Perch validation...


    Things I've tried

    Code
    1. <perch:form id="lead_magnet_form" method="post" action="<perch:content id="lm_campaign_name_slug">/downloads" app="perch_forms" class="form">
    2. // Removed novalidate attribute, browser takes care of validation
    3. // Prefer to use perch:error as I can customise messages and show them all at once.
    4. // Redirect is dynamic


    Code
    1. <perch:form novalidate id="lead_magnet_form" method="post" app="perch_forms" class="form">
    2. // Removed action attribute
    3. // Perch validation works
    4. // Redirect is not dynamic, needs to be set via settings in the CMS


    I suppose I could use perch:success tags, but it would involve changing the structure of the page template...



    Is there a way to use Perch form validation and action together?


    :/

  • Could you not add a manual redirection in your page file?


    Code
    1. if($campaignSlug = PerchUtil::post('lm_campaign_name_slug')) {
    2.     PerchSystem::redirect($campaignSlug.'/downloads')
    3. }

    and then have lm_campaign_name_slug as as hidden field

  • Hi Byron,


    Thanks for replying, that got me on the right track.


    However, I found the if statement triggered when I pressed submit - bypassing the form validation. I guess this is because lm_campaign_name_slug is present before the form is submitted. But it did get me thinking, I found this post, with a similar solution by hus_hmd.


    Inspired by both suggestions, I came up with this. Thanks Byron and Hussein 8)


    Using the code below I'm able to use novalidate on perch:form, Perch does all the validation I need, and the form redirects to a unique page. Perfect.


    I removed the action attribute from perch:form as it's no longer needed.