0

カートとして simpleCart.js を使用しています。sendform メソッドを使用して、カート データとシリアル化されたフォーム値の文字列を処理ページ (php5) に送信しています。私のフォームには 4 つのフィールドセットが設定されており、1 つのフィールドセットには支払いの詳細 (cc 番号、有効期限、cvv) が含まれています。そうは言っても、 $.serialize() 関数が実行された後、残りのフォーム フィールドを受け取っています。ただし、フォームの支払い情報ブロックからのデータがありません。フォーム名が投稿されていることがわかります。投稿されていないのは値だけです。指数の月と年は選択ボックスです。ポストされる値は選択された値ではなく、選択オプション リストの最初の選択肢です。

私のコードは次のとおりです。

シンプルカート関数:

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['extra'] 値が配列に解析され、「$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) ""
}

追加の配列では、フィールド ccnumber、expMo、expYr、および cvv がすべて空であることがわかりますが、他のフォーム値が投稿されています。

私は一生、問題がどこにあるのかを見つけることができません。1. フィールドに name 属性があることを確認しました。2. フィールドは form タグ内にあります。3. 壊れた html タグはありません。4. フィールドが投稿に含まれています。5. フォーム データをいじる検証はありません。

4

0 に答える 0