Jump to content

Redirect To a Specific Page Depending on Form Dropdown

Go to solution Solved by creedon,

Recommended Posts

Site URL: https://northshore-village-hoa.squarespace.com/dues-form

I am trying to set up a form to forward someone to a specific page after they choose a specific item from the drop down. I would like to point each option from the drop down - 1 month, 6 months, and 1 year to a different page for each one. 

I tried to work off of this thread -> Custom Redirect Forum Post, but am still unsuccessful. I have the code provided by @creedonin the header, but it's still not forwarding to the sites (they are random sites on my page for now, but will be the correct page in the near future). Any ideas?

Thanks!

Link to comment

The first thing you need to do is set the POST-SUBMIT REDIRECT. The URL should be either a default page. Or in your case it sounds like there is no default as each option will go to its own page. So the redirect should be to an error page you create saying something like sorry there was an error and how to recover, start over, contact you, etc. Whatever makes sense for your situation.

361384780_ScreenShot2021-03-27at8_25_37PM.png.65fd110ffe606c18970b993837fb895e.png

The code examples in that thread are very specific to the site, using references to elements that would only be on the site.

The good news is that the code can be adapted to others sites.

Give me a day or so to tweak the code to work for your site.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • Solution

In the thread you cite I have updated my October 19, 2020 code post.

Install that code and replace selectFormFieldName and optionUrlMappings.

    const selectFormFieldName = 'Length of Dues';
    
    const optionUrlMappings = {
    
      /*
      
        the format of each line is a select field option as entered in the SS
        form block interface and the post-submit redirect URL for the option
        
        */
        
      // '[enter select field option here]' : '[enter url here]',
      
      '1 Month'  : '/1-month',
      '6 Months' : '/6-months',
      
      // last or only item doesn't get a comma at end of line
      
      '1 Year'   : '/1-Year'
      
      }
      

Let us know how it goes.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 4 weeks later...
On 3/28/2021 at 8:06 AM, mmontg18 said:

Site URL: https://northshore-village-hoa.squarespace.com/dues-form

I am trying to set up a form to forward someone to a specific page after they choose a specific item from the drop down. I would like to point each option from the drop down - 1 month, 6 months, and 1 year to a different page for each one. 

I tried to work off of this thread -> Custom Redirect Forum Post, but am still unsuccessful. I have the code provided by @creedonin the header, but it's still not forwarding to the sites (they are random sites on my page for now, but will be the correct page in the near future). Any ideas?

Thanks!

i also tried it and successful 

Link to comment
  • 4 months later...
13 hours ago, creedon said:

@wcbailey

Are you married to having the form set to lightbox? My code wasn't designed to work with lightbox forms.

If not I have updated my cited code.

 

I wasn't sure how to use your updated code because I couldn't get it to work so I just tried to turn the lightbox off. It still isn't working so I am not sure what I broke.

Link to comment

@wcbailey

Two issues.

Remove the following line.

<script src="https://d1j8mu9lowy9zf.cloudfront.net/twcsl/0.1d7/twcsl.js"></script>

It is no longer needed for the current code.

The option url pairs should have no empty lines. Following is a partial example.

fbsfpsrc

Alabama
https://www.ckesn.com/state/Alabama

Alaska
https://www.ckesn.com/state/Alaska

Becomes.

fbsfpsrc
Alabama
https://www.ckesn.com/state/Alabama
Alaska
https://www.ckesn.com/state/Alaska

Your URLs could go from https://www.ckesn.com/state/Alabama to /state/Alabama, if you want. Either will work. The latter is an internal URL. You can even mix external and internal forms. The code doesn't care. It just blindly stuffs whatever you type into the proper place for SS to do it's magic with the redirect.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 2 years later...

Hi @creedon

Very new to using squarespace..

I am trying to get response specific redirects on my form 'Suite'

 https://star-chrysalis-ng7x.squarespace.com/new-page-5 

Password: Clive1

I have entered the code in the header, as well as in the code injection, I am not sure what the problem is being so new to this. I'm also not sure how to make it so you are able to view the code boxes for my site haha.

For context I am trying to redirect from the from answers to specific items within the store page, although I don't see this as introducing an issue as they still have unique urls / slugs. Please could you help me, and if so let me know how I can make the site accessible to you if it isn't already.

Thank you very much

 

<script>

  $( ( ) => {
  
    // begin dining outlet redirect
    
      const formSelectId = 'select-8f7a59bc-28ae-4a58-8321-c56c93ea83fc-field';
      
      const redirects = {
      
        /*
        
          enter options from select form field and redirect URL Slug or
          External URL
          
          */
          
        'Canoville Suite' : '/canoville1',
        'Bonetti Suite' : '/store-1/p/bonetti1'
        
        };
        
      // don't change anything beyond this point
      
      let $formSelect = $( '#' + formSelectId );
      
      // get the redirect form
      
      let $form = $formSelect.closest ( 'form' );
      
      $formSelect.change ( function ( ) {
      
        let url = $( this ).val ( );
        
        if ( url !== '' ) url = redirects [ url ];
        
        $form.attr ( 'data-success-redirect', url );
        
        } );
        
      /* end dining outlet redirect */
      
    } );
    

I tried variations of the url just in case it was that and I have no idea how to make it work

Link to comment
2 hours ago, Clive1 said:

I am not sure what the problem is being so new to this.

Unfortunately this code no longer works. I have added a note to my cited code post explaining the situation.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
15 minutes ago, creedon said:

Unfortunately this code no longer works. I have added a note to my cited code post explaining the situation.

That is a shame. Do you think it would still be possible to apply the same functionality to a drop down that is embedded in the page? As opposed to from a form?

Link to comment
14 minutes ago, Clive1 said:

Do you think it would still be possible to apply the same functionality to a drop down that is embedded in the page?

I know of no code that currently does this but yes I think it is possible.

If the select menu is built with custom code then JavaScript could redirect based on menu selection or a submit button.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.