我正在尝试为我的网站创建一个存款只读参考字段,并将其作为发票编号传递给贝宝以进行识别。参考号由DD/MM/YY格式的功能日期、名字&姓氏的第一个字符。(例如,2013年7月5日scottp)
我希望对所有可编辑字段进行必要的字段验证,并在用户输入功能日期后填充存款参考。。。。
我是PHP的新手,不确定从哪里开始,也不确定实现我想要的结果的最佳实践。
我使用的HTML表单包含以下代码:
<form id="depositForm" name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<div id="deposit-form" >
<h1>Paying your deposit is Simple.....</h1>
<p>Simply input all the details below, select your advised deposit option and click "Buy Now". It's that easy......</p>
<p>Note: All fields marked <h7>*</h7> are required. Any Errors will be highlighted <h7>Red</h7>.
<table>
<tr>
<td>
<label for="depositFirstname">*Firstname:</label>
<label for="depositSurname">*Surname:</label>
<label for="depositFunctiondate">*Function Date:</label>
<label for="depositOp">*Select deposit option:</label>
<label for="depositRef">Booking Reference:</label>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="XXXXXX">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="country" value="United Kingdom" />
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="item_name" value="Glimmer Nights Function Deposit">
<input type="text" name="first_name" id="depositFirstname" />
<input type="text" name="last_name" id="depositSurname" />
<input type="text" name="depositFunctiondate" id="depositFunctiondate" />
<select size="1" name="amount" id="depositOp" class="input" />
<option value="">Select</option>
<option name="amount" value="30.00">Option 1</option>
<option name="amount" value="50.00">Option 2</option>
<input type="text" name="invoice" id="depositRef" readonly="depositRef()" value="" />
</td>
</tr>
</table>
<p>Should you have any questions, please do not hesitate to contact us........</p>
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</div>
</form>
我认为你走在了正确的轨道上。请记住,表单要将其数据POST到<form>
标记的action
属性中列出的任何地址。在这种情况下,您将所有表单数据直接发送到PayPal。在发送数据之前,您没有机会运行任何PHP代码。两种选择:
1) 更改表单上的action
属性,并将数据POST到自己服务器上的PHP文件中。该文件将进行处理,然后向PayPal发送一个新的请求。
2) 这可能更容易。在用户单击"提交"之后,但在发送数据之前,使用javascript来制定发票编号。您可以通过在表单中添加onsubmit
属性来完成此操作
<form id="depositForm" name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" onsubmit="generateInvoiceNo();" method="post">
然后通过将<script>
块插入页面的<head>
区域来创建一个javascript函数:
<script>
function generateInvoiceNo(){
//get the date, user's first name and last initial
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
var datestr = curr_date + "/" + curr_month + "/" + curr_year.substr(2)
var firstname = document.getElementById('depositFirstname').value;
var lastname = document.getElementById('depositLastname').value;
//generate invoice number
var invoicenum = datestr + firstname + lastname.substr(0,1);
//put the invoice number into a hidden field on the form
document.getElementById('depositRef').value = invoicenum;
}
</script>
警告:我还没有测试上面的代码,但它应该会让你开始。