title: How to connect my search box to rotten tomatoes API search
body: <p>How do I get my search box connected with the Rotten Tomatoes API so I can do a search in my web page and it returns the results from Rotten Tomatoes?</p>
  
  <p>I added the <code>$userSearch</code> variable in the PHP section. And I put that variable in the <code>urlencode</code> function. I am a bit lost on how to proceed. I think I need to use AJAX jQuery, do I need to create a JavaScript file that contains the code to hit the API and have an "action" inside my search box definition? I am a bit confused on how to go about this and am having trouble finding an example. I am building this off the 
  <a href="http://developer.rottentomatoes.com/docs/read/json/v10/examples" rel="nofollow">Rotten Tomatoes PHP Example</a>.</p>
  
  <p>Here is my code with a "Mouse" search hard coded:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;form method="post" action="www.websitehere.com/folderhere/"
                name="searchform" id="searchform"&gt;
  
              &lt;label for="Search"&gt; Search: &lt;/label&gt;
              &lt;input type="text" id="search" name="myName" placeholder="Search for movie" 
                     required="required" style="width: 520px" /&gt;
  
              &lt;label for="category" id="category"&gt;Category&lt;/label&gt;
              &lt;select&gt;
                  &lt;option value="title" selected="selected"&gt;Movie Title&lt;/option&gt;
                  &lt;option value="director"&gt;Director&lt;/option&gt;
                  &lt;option value="genre"&gt;Genre&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type="submit" value="Search" id="searchbtn"&gt;
              &lt;input type="submit" value="Add" id="searchbtn"&gt;
              &lt;p&gt;&lt;/p&gt;
              &lt;div id="search_results"&gt;Local Search results&lt;/div&gt;
  
          &lt;/form&gt;
  
          &lt;?php
          $userSearch = 'Mouse';
          $apikey = 'myapikeyhiddenforprivacy';
          $q = urlencode($userSearch); // make sure to url encode an query parameters
  // construct the query with our apikey and the query we want to make
          $endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&amp;q=' . $q;
  
  // setup curl to make a call to the endpoint
          $session = curl_init($endpoint);
  
  // indicates that we want the response back
          curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  
  // exec curl and get the data back
          $data = curl_exec($session);
  
  // remember to close the curl session once we are finished retrieveing the data
          curl_close($session);
  
  // decode the json data to make it easier to parse the php
          $search_results = json_decode($data);
          if ($search_results === NULL)
              die('Error parsing json');
  
  // play with the data!
          $movies = $search_results-&gt;movies;
          echo '&lt;ul&gt;';
          foreach ($movies as $movie) {
              echo '&lt;li&gt;&lt;a href="' . $movie-&gt;links-&gt;alternate . '"&gt;' . $movie-&gt;title . " (" . $movie-&gt;year . ")&lt;/a&gt;&lt;/li&gt;";
              echo '&lt;img src="' . $movie-&gt;posters-&gt;detailed . ' "/&gt;&lt;br&gt;';
          }
          echo '&lt;/ul&gt;';
          ?&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>