Variables jekyll将变量传递到表单页
我试图找到一种方法,用jekyll创建一个单独的预订表单。 例如,我在我的旅游详情页面上有一个预订按钮 当用户单击该按钮时,我想知道是否有方法将参数传递到预订页面,以便显示例如名称--价格--等等。。。这次旅行的目的地Variables jekyll将变量传递到表单页,variables,parameters,jekyll,Variables,Parameters,Jekyll,我试图找到一种方法,用jekyll创建一个单独的预订表单。 例如,我在我的旅游详情页面上有一个预订按钮 当用户单击该按钮时,我想知道是否有方法将参数传递到预订页面,以便显示例如名称--价格--等等。。。这次旅行的目的地 我不知道怎么做,甚至不知道这是否可能。是否有足够聪明的人能为我指明正确的方向(如果有)?是的,这是可能的,但由于Jekyll是静态的,您必须在客户端执行此操作 解释 巡更页面(tour.html): 此表单自动填充从tour.html传递的参数 然后可以将其指向表单服务,如,或任
我不知道怎么做,甚至不知道这是否可能。是否有足够聪明的人能为我指明正确的方向(如果有)?是的,这是可能的,但由于Jekyll是静态的,您必须在客户端执行此操作 解释 巡更页面(
tour.html
):
此表单自动填充从tour.html
传递的参数
然后可以将其指向表单服务,如,或任何表单服务,以交付提交的数据
注意:提交表单时,某些服务需要重定向到回调页。
然后,您需要创建另一个页面(例如:thankyou.html
),在该页面中,您必须解析url传递的数据并将其呈现给用户
---
title: tours
layout: page
tour:
name: Flying with eagles
description: text here
price: 120€
---
{% capture url %}n={{ page.tour.name | uri_escape }}&p={{ page.tour.price | uri_escape }}{% endcapture %}
<h2>{{ page.tour.name }} ({{ page.tour.price }}) - <a href="tour-form.html?{{ url }}">Book me for this tour!</a></h2>
<p>{{ page.tour.description }}</p>
<h2>{{ page.tour.name }} ({{ page.tour.price }}) - <a href="tour-form.html?{{ url }}">Book me for this tour!</a></h2>
<h2>Flying with eagles (120€) - <a href="tour-form.html?n=Flying%20with%20eagles&p=120%E2%82%AC">Book me for this tour!</a></h2>
---
title: tour form
layout: page
---
<form accept-charset="UTF-8" action="" method="POST">
<input type="text" name="tourName" value="">
<input type="text" name="tourPrice" value="">
<input type="email" name="email" placeholder="Your Email">
<input type="text" name="name" placeholder="Your Name">
<button type="submit">Submit</button>
</form>
<script>
// this script will automatically fill name and price fields
// depending on what's passed in the url
var fillForm = function () {
var queryString = document.location.search.split("+").join(" ");
var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(queryString)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
if (params.n == undefined && params.p == undefined){
// no value in the query string
// here you have to manage this use case : redirect or print a message to user
}else{
// filling form fields with query string values
document.getElementsByName('tourName')[0].value = params.n;
document.getElementsByName('tourPrice')[0].value = params.p;
}
} ();
</script>