get product id as URL parameter for contact form

Solved

get product id as URL parameter for contact form

Mazhardev
Visitor
2 0 0

I have a form if any clients want a product in a big quantity so they can submit a form to discuss the price.
Want to get the product id so we can get identify the user's product
For that I want when user click on the button for a form so the product id will get as URL parameter and the form get and fill the product id automatically from the URL

Accepted Solution (1)
gr_trading
Shopify Partner
1919 145 199

This is an accepted solution.

Hey @Mazhardev ,

 

I got your question correctly. So your question has two-part

 

1. Create a Request a quote link on the product page. To achieve it please put below code just after the buy button code in main-product.liquid, which will lead your user to the contact us form.

<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>

 

2. Read the querystring to fill contact us page, for that please refer to and the previous answer, on how to get querystring on the page.

 

Hope it help! 

For any custom development WhatsApp or connect at Email ID: [email protected] for quick consultation. | Shopify Free codes
To support Buy Me a Coffee

View solution in original post

Replies 5 (5)

gr_trading
Shopify Partner
1919 145 199

Hi @Mazhardev ,

 

Please use the below script to get the product id from the URL.

 

<script>
      function getQuerystringNameValue(name) {
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if( results == null )
          return null;
        else        
          return decodeURIComponent(results[1].replace(/\+/g, " "));
      }

var _productid = getQuerystringNameValue("formid");
        if(_productid != null){
// code
        }
</script>

 

For any custom development WhatsApp or connect at Email ID: [email protected] for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Mazhardev
Visitor
2 0 0

Thanks for your reply!
but I think you did not understand what I want or maybe I cant convey my question correctly

I need to pass the product id as a URL parameter for contact form
You can see the example on this page if you want
https://www.twm-bv.com/en/bikes/1004350-amigo-flip-18-inch-265-cm-boys-coaster-brake-black-blue/
Here you can see the button "Request an Offer" click on it and then check it pass the product id to form as "ean number"
Let me know if you have any question 
Thanks

gr_trading
Shopify Partner
1919 145 199

This is an accepted solution.

Hey @Mazhardev ,

 

I got your question correctly. So your question has two-part

 

1. Create a Request a quote link on the product page. To achieve it please put below code just after the buy button code in main-product.liquid, which will lead your user to the contact us form.

<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>

 

2. Read the querystring to fill contact us page, for that please refer to and the previous answer, on how to get querystring on the page.

 

Hope it help! 

For any custom development WhatsApp or connect at Email ID: [email protected] for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
Apexmanagement
Visitor
1 0 0

Hi

I found this thread and i have some questions about this:

 

1.  I need to have the product title and the color variant into this string:

 

<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>

 

2: Where do i put this script?:

 

<script>
function getQuerystringNameValue(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return null;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}

var _productid = getQuerystringNameValue("formid");
if(_productid != null){
// code
}
</script>

 

3. Do i need to change anything in the Contact form?

 

THanks in advance!

HK

 

 

 

 

 

 

gr_trading
Shopify Partner
1919 145 199

Hi @Apexmanagement 

 

Yes, you have to create two fields for title and color which will be passed into the URL.

 

Also have to amend the script to read the value from URL and assign it to form.

For any custom development WhatsApp or connect at Email ID: [email protected] for quick consultation. | Shopify Free codes
To support Buy Me a Coffee