title: how to retrieve form posts via json
body: <p>Hey all i am trying to figure out how to go about getting my forms values that are sent via ajax json in the php script.</p>
  
  <pre><code>$.ajax
  ({
      type: "POST",
      url: "http://www.xxx.com/cart/gateway",
      dataType: 'json',
      async: false,
      contentType: "json",
      data: JSON.stringify({ "unique_id": $("#order_unique_id").val(), "name_on_card" : $("#name_on_card").val(), "card_number" : $("#card_number").val(), "expiry_date" : $("#expiry_date").val(), "cvv_code" : $("#cvv_code").val() }),
      success: function (data) {
          if (data &amp;&amp; data != null &amp;&amp; data["success"] != null &amp;&amp; data["orderid"]) {
                  processSuccess(data["orderid"]);
              } else if (data &amp;&amp; data != null &amp;&amp; data["error"] != null) {
                  processError(data["error"]);
              } else {
                  processError('unknown');
              }
              processing = false; 
      }
  })
  </code></pre>
  
  <p>Currently it has an error but thats only because its looking for a POST value from a form. Here is that code:</p>
  
  <pre><code> public function __construct(&amp;$page, $params) {
      $page-&gt;cart = new theCart();
      $page-&gt;cart-&gt;set_form();
  
      switch($action){
          case 'gateway':
              $this-&gt;checkoutCart($page);
              break;
  
   ...}
  
   function set_form()
  {
  $this-&gt;setFormValue('b_email');
  $this-&gt;setFormValue('b_first_name');
  $this-&gt;setFormValue('b_last_name');
  .....etc etc
  //ADDED 7/25/2012
  $this-&gt;setFormValue('name_on_card'); 
  $this-&gt;setFormValue('card_number'); 
  $this-&gt;setFormValue('expiry_date'); 
  $this-&gt;setFormValue('cvv_code'); 
  $this-&gt;setFormValue('order_unique_id'); 
  
  $this-&gt;verified = false;
   }
  
   function setFormValue($name){
     if(isset($_POST[$name])){
       $this-&gt;$name = trim($_POST[$name]);
     }
   }
  
   private function checkoutCart(&amp;$page){
      $page-&gt;part-&gt;body-&gt;content_html = $this-&gt;pPay($page, $this-&gt;getPay());
  }
  
   private function getPay(){
      //echo 'getP== ' . json_decode( $_POST[ 'unique_id' ], true );
      echo 'getP== ' . $_POST['unique_id'];
  
      return array(
          'unique_id' =&gt; $_POST['unique_id'],
          'name_on_card' =&gt; $_POST['name_on_card'],
          'card_number' =&gt; $_POST['card_number'],
          'expiration_date' =&gt; $_POST['expiry_date'],
          'cvv_code' =&gt; $_POST['cvv_code']
      );
  }
  </code></pre>
  
  <p>I am not getting any value for <strong>$_POST['unique_id']</strong> above.</p>
  
  <p>The original post code was this:</p>
  
  <pre><code>$.post("http://www.xxx.com/cart/gateway",
          {
              unique_id:$("#order_unique_id").val(),
              name_on_card:$("#name_on_card").val(),
              card_number:$("#card_number").val(),
              expiry_date:$("#expiry_date").val(),
              cvv_code:$("#cvv_code").val()   
          },
          function(data) {
              if (data &amp;&amp; data != null &amp;&amp; data["success"] != null &amp;&amp; data["orderid"]) {
                  processSuccess(data["orderid"]);
              } else if (data &amp;&amp; data != null &amp;&amp; data["error"] != null) {
                  processError(data["error"]);
              } else {
                  processError('unknown');
              }
              processing = false;
          },
          "json"
  );
  </code></pre>
  
  <p>But that did not work as it could not be formatted correctly (its looking for a json response.. that seemed to put it in ?blah=blah&amp;blah=blah.... **BUT that did produce the values it was looking for in the $.POST part of the code.. but its worthless if the error goes to not being in the wanted format (json).</p>
  
  <p>How can i correct this from happening?</p>