我正在尝试为我的网站创建一个存款只读参考字段,并将其作为发票号码传递给PayPal。用于识别。参考编号。由函数日期填充,格式为DD / MM / YY,firstname&姓氏的第一个字。 (例如05/07 / 13scottp)
我想在所有可编辑字段上进行必要的字段验证,并在用户输入功能日期后填充存款参考....
我是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>
答案 0 :(得分:0)
我认为你走在正确的轨道上。请注意,您的表单会将其数据发布到action
标记的<form>
属性中列出的任何地址。在这种情况下,您将所有表单数据直接发送到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>
警告:我没有测试过上面的代码,但它应该让你入门。