title: How to use cURL to POST form values on form using JS
body: <p>*<em>Sorry for the long post</em> *
  I'm using cURL in PHP to <code>post</code> some form fields in effort to return the result of the <code>post</code> Need some help as the form is somewhat unusual. </p>
  
  <h1>cURL Script</h1>
  
  <pre><code> $ch = curl_init();
   $data = array('field_1_name' =&gt; 'field_value',
                 'field_2_name' =&gt; 'field_value',
                 'field_3_name' =&gt; 'field_value',
                ); 
   curl_setopt($ch, CURLOPT_URL,'http://url.com');  
   curl_setopt ($ch, CURLOPT_POST, 1);
   curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $fp = fopen('data.php', 'w');
   curl_setopt($ch, CURLOPT_FILE, $fp);
   curl_exec ($ch);
   curl_close ($ch);
   fclose($fp);
  </code></pre>
  
  <h1>Things you should be aware of</h1>
  
  <ol>
  <li>The fields are not <code>text-fields</code> but rather a combination of <code>radio</code> and <code>dropdown</code> fields.</li>
  <li>The form contains <code>JS</code> but firebug console is not showing <code>AJAX</code> posts - instead the form works with <code>SESSIONS</code> and <code>HTTP-CACHE</code> data.</li>
  <li>Once a form field is selected, the page seems to <code>reload</code> and the values of the next dropdown are inserted. (Again firebug is not showing this as an <code>AJAX</code> request.)</li>
  </ol>
  
  <h1>Here's an example of a <code>dropdown</code> field on the form</h1>
  
  <pre><code>&lt;select name="field_name" onchange="document.getElementById('uploadForm').action.value='RELOAD';document.getElementById('uploadForm').reloadTrigger.value='trigSize';document.getElementById('uploadForm').submit();"&gt;
     &lt;option value="option_1"&gt;option_1&lt;/option&gt;
     &lt;option value="option_2"&gt;option_2&lt;/option&gt;
     &lt;option value="option_3"&gt;option_3&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Notice the <code>onChange</code> event which triggers the reloaded page with the next <code>dropdwon</code> and its' respective <code>options</code>.</p>
  
  <h1>What I'm trying to accomplish</h1>
  
  <p>Each <code>dropdown</code> field contains various options. Based on the combination selected on the form, the final page reload returns a <strong>price based on these options selected</strong>. I need to save the <strong>price</strong> and the <strong>options selected</strong> to my database.</p>
  
  <p>So my database looks like this:</p>
  
  <pre><code>option_1   |   option_2   |   option_3   |   price   |
  field_1    |   field_2    |   field_3    |    25     |
  </code></pre>
  
  <p>I'm including all this information because someone with <strong>experience</strong> can possibly point me in a <em>better</em> direction (meaning: toots/libraries/tutorials/etc.) I'm not sure if <code>cURL</code> is right for this job. I prefer to work with <code>PHP</code>. So what do you guys think? Thank you for your time and suggestions. I welcome and appreciate all helpful information.</p>
  
  <p>--Side Note--
  I wrote a script in <code>RUBY</code> using <code>WATIR-WebDriver</code> that is successfully scraping the information, but is working way too slow. Each product has on average of 5,000 different combinations and this method was only returning about 10 per minute. (FAIL)</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>Just to clarify. This form is not on my server and is not owned or operated by me. I'm intending to scrape the data returned by the form.</p>