Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Custom Redirect Based on Form Selection


MelissaHostetter

Question

Site URL: https://www.treatyoakdistilling.com/

I am trying to create a custom form that will redirect users to different landing pages based on the selection they make. The form is a drop down asking visitors to select their state. I would like the form to re-direct them to a specific landing page based on which state they selected. Help! 

Edited by MelissaHostetter
Link to comment

14 answers to this question

Recommended Posts

  • 0

@creedon Thank so much, you rock. I tried inserting the code as directed and still not seeing results. 

Perhaps there is a simpler solution. There are only 3 states that need to be re-directed to a different page so right I have the form "submit" set to redirect to the URL that applies to all states except CA, TX and IL , this is what that code looks like from SquareSpace: 

 <form data-form-id="5f8da955f46d167ee8ce5578" data-success-redirect="https://shoptreatyoak.com/" autocomplete="on" method="POST" action="https://hawk-sprout-ry8m.squarespace.com" onsubmit="return (function (form) {

  Y.use('squarespace-form-submit', 'node', function usingFormSubmit(Y) {

    (new Y.Squarespace.FormSubmit(form)).submit({

      formId: '5f8da955f46d167ee8ce5578',

      collectionId: '5f8da8994339540352e6f741',

      objectName: 'page-5f8da8994339540352e6f741'

    });

  });

  return false;

})(this);" id="yui_3_17_2_1_1603213358956_601">

 

 

Is there something that can be done to offer an alternate redirect when  

<option value="California">California</option>

 <option value="Illinois">Illinois</option>

  <option value="Texas">Texas</option>

 

Link to comment
  • 0

Sure my code can be modified but the core behaviour will still be the same. It needs to replace the redirect url for CA, IL and TX. We don't want to mess with the SS code it actually handles the form submit process.

My code just substitutes the redirect URL. We need to figure out why my code isn't running.

Is the code still there or did you take it out? I'm not seeing it on the page.

Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support!

Link to comment
  • 0

Updated code that is closer to what I think @MelissaHostetter wants.

<script>

  $( ( ) => {
  
    const stateUrlRedirect = {
    
      dataFormId : '5f8da955f46d167ee8ce5578',
      formSelectId : 'select-yui_3_17_2_1_1603057474472_404878-field',
      states : [ 'California', 'Illinois', 'Texas' ],
      redirectUrl : 'https://www.squarespace.com/'
      
      };
      
    // don't change anything beyond this point
    
    let $stateUrlRedirectForm = $( '[data-form-id="' +
    
      stateUrlRedirect.dataFormId + '"]' );
      
    stateUrlRedirect.originalRedirectUrl = $stateUrlRedirectForm.attr (
    
      'data-success-redirect' );
      
    $( '#' + stateUrlRedirect.formSelectId )
    
      .change ( function ( ) {
      
        let url = stateUrlRedirect.states.includes ( $( this ).val ( ) ) ?
        
          stateUrlRedirect.redirectUrl : stateUrlRedirect.originalRedirectUrl;
          
        $stateUrlRedirectForm.attr ( 'data-success-redirect', url );
        
        } );
    } );
    
  </script>

 

Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support!

Link to comment
  • 0
1 hour ago, EENewHampshire said:

I am looking to do a very similar thing and was wondering if you could help me out as well.

I and others would be happy to take a look at your issue.

I suggest starting a new thread on the forum, describe what you need and then we can take a look. Be sure to post the URL for the page with your form.

If your site is not public please set up a site-wide password, if you've not already done so. Also post the password.

Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support!

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...