1 javascript asp.net post sitecore
我目前正在使用Sitecore,我正在尝试创建一个POST操作,使用表单收集的信息将信息发布到支付站点.知道Sitecore剥离html标签会让它变得有点痛苦.经过一些搜索,我发现我可以使用javascript创建一个动态表单并发送,这将是我的问题的答案,遗憾的是我是一个javscript新手,虽然我能够破译javacript我无法发布.
任何输入或基本信息的链接将非常感激.
这是我的表单代码:
<fieldset id="PayForm" > <br>
<!--Store Settings-->
<input type="Hidden" name="ps_store_id" value="******" />
<input type="Hidden" name="hpp_key" value="*******" />
<input type="Hidden" name="charge_total" value="40.00" />
<!--Item Details-->
<input type="hidden" value="1" name="quantity1" />
<input type="hidden" value="Public Speaking" name="description1" />
<select name="id1">
<option>Select Date...</option>
<option value="Sep22PubSp"> Sept-22
</option>
<option value="Sep29PubSp"> Sept-29
</option>
<option value="Nov19PubSp"> Nov- 19
</option>
</select>
<br />
<input type="hidden" value="40" name="price1" />
<!--Student Details-->
First Name<input type="text" name="ship_first_name" value="First Name" /> Last Name <input type="text" name="ship_last_name" value="Last Name" /> <br />
Student ID#: <input type="text" name="cust_id" value="Student ID" /><br />
Email<input type="text" name="email" value="Email" /> <br />
CCID<input type="text" name="note" value="CCID" /><br />
</fieldset>
Run Code Online (Sandbox Code Playgroud)
这是我的Javascript的样子
<script type="text/javascript">// <![CDATA[
function post_to_url() {
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "******WEBSITE HERE*******");
form.setAttribute("target", "tfl");
var fieldset = document.getElementById("PayForm");
var copy = fieldset.cloneNode(true);
var description1 = document.getElementById("type_description1_form");
var ship_first_name = document.getElementById("type_ship_first_name_form");
var ship_last_name = document.getElementById("type_ship_last_name_form");
var cust_id = document.getElementById("cust_id");
var email = document.getElementById("type_email_form");
var note = document.getElementById("type_note_form");
var description1Input = document.createElement("input");
description1Input.setAttribute("name", "type_description1");
description1Input.setAttribute("value", description1.options[description1.selectedIndex].value);
var ship_first_nameInput = document.createElement("input");
destinInput.setAttribute("name", "type_ship_first_name");
destinInput.setAttribute("value", ship_first_name.options[ship_first_name.selectedIndex].value);
var ship_last_nameInput = document.createElement("input");
ship_last_nameInput.setAttribute("name", "type_ship_last_name");
ship_last_nameInput.setAttribute("value", ship_last_name.options[ship_last_name.selectedIndex].value);
var cust_idInput = document.createElement("input");
cust_idInput.setAttribute("name", "type_cust_id");
cust_idInput.setAttribute("value", cust_id.options[cust_id.selectedIndex].value);
var emailInput = document.createElement("input");
emailInput.setAttribute("name", "type_email");
emailInput.setAttribute("value", email.options[email.selectedIndex].value);
var noteInput = document.createElement("input");
noteInput.setAttribute("name", "type_note");
noteInput.setAttribute("value", note.options[note.selectedIndex].value);
form.appendChild(copy);
form.appendChild(originInput);
form.appendChild(destinInput);
document.body.appendChild(form);
form.submit();
};
// ]]></script>
Run Code Online (Sandbox Code Playgroud)
感谢您的时间!
您的问题不在于Sitecore剥离表单标记.您的问题是您正在使用ASP.Net webforms,这需要对表单进行特殊考虑.这是因为您已经有一个表单标记,其属性runat ="server"用于显示sitecore的组件.
也就是说,你编写的javascript将永远不会在sitecore的环境中工作.您根本无法在ASP.Net webform中嵌套html表单.
请参阅此文章,了解修改ASP.net模板以支持表单提交的基础知识:http: //www.sitepoint.com/net-form-processing-basics/ 或者,您可以按照预期的方式创建表单(再次,没有javascript)作为纯HTML,并将其包含在IFrame中的sitecore组件模板(.ascx控件)中.
归档时间: |
|
查看次数: |
482 次 |
最近记录: |