2014-12-02 69 views
0

我們希望通過電子郵件中的contactform顯示網站的網址。如何在shopify聯繫表格中捕獲網站地址

我們使用shopify表單模板

<div class="contactform"> 
    <input type="text" name="contact[name]" value="" size="22" tabindex="1" placeholder="Vor- und Nachname"> 
    <input type="email" name="contact[email]" value="" size="22" tabindex="1" required="required" placeholder="Mailadresse"> 
    <input type="text" name="contact[firma]" value="" size="22" tabindex="1" placeholder="Firma"> 
    <input type="text" name="contact[auflage]" value="" size="22" tabindex="1" placeholder="Auflage"> 
    <textarea rows="8" cols="75" name="contact[nachricht]" placeholder="Nachricht"></textarea> 
    <input type="submit" id="contactFormSubmit" value="Angebot anfragen" />    
    </div> 
+0

@約翰 - 孔德舊線,但Shopify不允許解析的PHP在他們的主題系統中的任何地方,這個問題是有效的,因爲在Shopify的答案從http://stackoverflow.com/questions/6768793/get-the-full-url-in-php將無法正常工作。它將改爲註釋掉php標籤並將其轉換爲內聯評論。 – 2015-10-25 15:49:33

回答

0
<p><?= htmlentities($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?></p> 
+0

此代碼在Shopify Liquid模板中解析爲以下內容: '

<! - ?= htmlentities($ _SERVER ['HTTP_HOST']。$ _SERVER ['REQUEST_URI'])? - >

' – 2015-10-25 15:59:34

2

創建一個隱藏的輸入

<input type="hidden" value="" id="hiddenurl" name="url"/> 

,並添加JavaScript:

var a = document.getElementById('hiddenurl'); 
a.value = window.location.href; 
+0

截至Oct 2015這個答案似乎是最可靠的。下一個最佳選擇是檢查當前模板類型,即「頁面」,「博客」,「集合」的代碼片段。但是這會漏掉某些URL,比如404,'homepage','/ collections/all /'等等。 https://github.com/joshuacc/Shopify-Snippets/blob/master/find-current-url.liquid – 2015-10-25 15:55:19