title: Post html form to php to rest api
body: <p>I am trying to post a form to a php file but the php doest seem to be able to read the post data. Noob here, what am I doing wrong</p>
  
  <p>Html Form</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Voucher Generator&lt;/title&gt;
  &lt;link rel="stylesheet" type="text/css" href="view.css" media="all"&gt;
  &lt;script type="text/javascript" src="view.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body id="main_body" &gt;
  
  &lt;img id="top" src="top.png" alt=""&gt;
  &lt;div id="form_container"&gt;
  
  &lt;h1&gt;&lt;a&gt;Voucher Generator&lt;/a&gt;&lt;/h1&gt;
  &lt;form id="form_71867" class="appnitro"  method="post" action="post.php"&gt;
  &lt;div class="form_description"&gt;
  &lt;h2&gt;Voucher Generator&lt;/h2&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;/div&gt;                      
  &lt;ul &gt;
  
  &lt;li id="li_1" &gt;
  &lt;label class="description" for="element_1"&gt;Mobile &lt;/label&gt;
  &lt;div&gt;
  &lt;input id="element_1" name="simu" class="element text medium" type="text" maxlength="255" value=""/&gt; 
  &lt;/div&gt; 
  &lt;/li&gt;       &lt;li id="li_2" &gt;
  &lt;label class="description" for="element_2"&gt;Package Amount &lt;/label&gt;
  &lt;div&gt;
  &lt;input id="element_2" name="pesa" class="element text medium" type="text" maxlength="255" value=""/&gt; 
  &lt;/div&gt; 
  &lt;/li&gt;
  
  &lt;li class="buttons"&gt;
  &lt;input type="hidden" name="form_id" value="71867" /&gt;
  
  &lt;input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
  &lt;/form&gt; 
  &lt;div id="footer"&gt;
  Generated by &lt;a href="http://www.phpform.org"&gt;pForm&lt;/a&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;img id="bottom" src="bottom.png" alt=""&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  //POST DATA
  $mobile = $_POST['simu'];
  $amount = $_POST['pesa'];
  //API Url
  $url = 'http://localhost:8080/k2/ipn.php';
  
  //Initiate cURL.
  $ch = curl_init($url);
  
  //The JSON data.
  $jsonData = array(
      'sender_phone' =&gt;  $mobile,
      'amount' =&gt;  $amount
  );
  
  //Encode the array into JSON.
  $jsonDataEncoded = json_encode($jsonData);
  
  //Tell cURL that we want to send a POST request.
  curl_setopt($ch, CURLOPT_POST, 1);
  
  //Attach our encoded JSON string to the POST fields.
  curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
  
  //Set the content type to application/json
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
  
  //Execute the request
  $result = curl_exec($ch);
  </code></pre>
  
  <p>The php file is posting  "$mobile" &amp; "$amount" to the endpoint instead of the actual values. 
  The whole process is actually;
  -  a user fills the html form which send the data to the php file 
  - php file converts it to json and post to the api endpoint. </p>
  
  <p>I can't find any information on posting json from a form directly </p>