我使用simpleCart.js作为购物车,我使用sendform方法将购物车数据和序列化的表格值字符串发送到我的处理页面(php5)。 我的表单设置有4个字段集,一个字段集包含付款详细信息:(cc编号,exp.date,cvv)。据说我在运行$ .serialize()函数后收到了其余的表单字段。但是我错过了表单付款信息块中的数据。我可以看到表单名称已经发布,它只是未发布的值。 exp月份和年份是选择框,发布的值不是选定的值,只是选择选项列表中的第一个选项。
我的代码如下:
simpleCart函数:
checkout: {
type: "SendForm",
// url: "https://secure.authorize.net/gateway/transact.dll", // Production URL
//url: "https://test.authorize.net/gateway/transact.dll", // Test URL
url: "checkout.php?action=confirm", // our post url
//url: url,
method: "POST",
extra_data: {
extra: $('form#checkOutConfirmForm').serialize(),
testItem: 'test Item',
check_out: "Yes"
}
},
表单标记本身:
<form id="checkOutConfirmForm" method="post" action="" name="checkOutConfirmForm">
有问题的表单字段集:
<fieldset>
<legend>Payment info</legend>
<ul>
<li class="field">
<input class="input normal" name="ccnumber" id="ccnumber" type="text" placeholder="Credit Card #" required="required">
</li>
<li class="field">
<div class="picker">
<select required="required" name="expMo" id="expMo">
<option value="#" disabled> - MM - </option>
<?php if(isset($expMo)) {
echo '<optgroup label="Current"><option selected="selected">'.$expMo.'</option></optgroup>';
} ?>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
</div>
<div class="picker">
<select required="required" name="expYr" id="expYr">
<option value="#" disabled> - YYYY - </option>
<?php if(isset($expYr)) {
echo '<optgroup label="Current"><option selected="selected">'.$expYr.'</option></optgroup>';
} ?>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
<option>2021</option>
</select>
</div>
</li>
<li class="field">
<input type="text" class="input xnarrow<?php if (in_array('cvv', $errors)) { echo ' labelerror'; } ?>" maxlength="3" name="cvv" placeholder="CVV" id="cvv" value="<?php echo (isset($cvv)) ? $cvv : ''; ?>">
</li>
</ul>
</fieldset>
在checkout.php中的我从我的帖子值中获取额外的字符串并将它们解析为自己的数组:
$extra = $_POST['extra'];
$extraFields = array();
parse_str($extra,$extraFields);
如果我运行var_dump,我会看到: 完整的帖子数组:
array(16) {
["currency"]=>string(3) "USD"
["shipping"]=>string(1) "0"
["tax"]=>string(1) "0"
["taxRate"]=>string(1) "0"
["itemCount"]=>string(1) "2"
["item_name_1"]=>string(11) "Fiber 1234®"
["item_quantity_1"]=>string(1) "1"
["item_price_1"]=>string(2) "55"
["item_options_1"]=>string(52) "thumb: /cb2014-II/img/products/Fiber1234.jpg, pid: 4"
["item_name_2"]=>string(9) "eAc 1234®"
["item_quantity_2"]=>string(1) "1"
["item_price_2"]=>string(5) "42.95"
["item_options_2"]=>string(40) "pid: 27, thumb: img/products/eAC1234.jpg"
["extra"]=>string(473) "x_first_name=Stephen&x_last_name=Nielsen&phone=801-703-7467&fax=&email=stephen.nielsen%40creativebioscience.com&company=MoJu+Consulting+and+Design&ccnumber=&expMo=1&expYr=2014&cvv=&address1=6543+Daffodil+Way&address2=&city=West+Jordan&state=UT&zip=84081&country=USA&addressee_firstName=&addressee_lastName=&shipping_address1=&shipping_address2=&shipping_city=&shipping_state=&shipping_zip=&shipping_country=&checkoutConfirm=1&x_amount=&num_units=&x_test_request=yes&cc_num="
["testItem"]=>string(9) "test Item"
["check_out"]=>string(3) "Yes"
}
将$ _POST [&#39;额外&#39;]值解析为数组并转储&#34; $ extraFields []&#34;
array(29) {
["x_first_name"]=>string(7) "Stephen"
["x_last_name"]=>string(7) "Nielsen"
["phone"]=>string(12) "801-703-7467"
["fax"]=>string(0) ""
["email"]=>string(38) "stephen.nielsen@creativebioscience.com"
["company"]=>string(26) "MoJu Consulting and Design"
["ccnumber"]=>string(0) ""
["expMo"]=>string(1) "1"
["expYr"]=>string(4) "2014"
["cvv"]=>string(0) ""
["address1"]=>string(17) "6543 Daffodil Way"
["address2"]=>string(0) ""
["city"]=>string(11) "West Jordan"
["state"]=>string(2) "UT"
["zip"]=>string(5) "84081"
["country"]=>string(3) "USA"
["addressee_firstName"]=>string(0) ""
["addressee_lastName"]=>string(0) ""
["shipping_address1"]=>string(0) ""
["shipping_address2"]=>string(0) ""
["shipping_city"]=>string(0) ""
["shipping_state"]=>string(0) ""
["shipping_zip"]=>string(0) ""
["shipping_country"]=>string(0) ""
["checkoutConfirm"]=>string(1) "1"
["x_amount"]=>string(0) ""
["num_units"]=>string(0) ""
["x_test_request"]=>string(3) "yes"
["cc_num"]=>string(0) ""
}
在额外数组中,你可以看到字段ccnumber,expMo,expYr和cvv都是空的,但是我发布了其他表单值。
我不能为我的生活找到问题所在。 1.我已确认这些字段具有name属性。 2.字段位于表单标记内。 3.没有破坏的html标签。 这些字段包含在帖子中。 5.没有验证表格数据的混乱。