I am using simpleCart.js as a cart, I am using the sendform method to send the cart data and a serialized string of form values to my processing page (php5). My form is set up with 4 fieldsets, one fieldset contains the payment details: (cc number, exp. date, cvv). With that said I am receiving the rest of the form fields after the $.serialize() function is ran. I am however missing the data from the payment info block of the form. I can see the form names have been posted, it is just the values that are not posted. THe exp month and year are select boxes, the values that are being posted are not the selected values, just the first choices in the select option list.
My code follows:
The simpleCart function:
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"
}
},
The form tag itself:
<form id="checkOutConfirmForm" method="post" action="" name="checkOutConfirmForm">
The form fieldset in question:
<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>
in checkout.php I get the extra string from my post values and parse them into there own array:
$extra = $_POST['extra'];
$extraFields = array();
parse_str($extra,$extraFields);
If I run a var_dump I see: The post array in full:
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"
}
And the $_POST['extra'] value parsed into an array and dumped "$extraFields[]"
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) ""
}
In the extra array you can see the fields ccnumber, expMo, expYr and cvv are all empty but I am getting the other form values posted.
I cannot for the life of me find where the issue lies. 1. I have confirmed that the fields have a name attribute. 2. The fields are inside the form tags. 3. There are no broken html tags. 4. The fields are being included in the post. 5. There is no validation messing with the form data.