title: Send and print PHP Array result on one page?
body: <p>I am a PHP beginner and today I started learning Mootools. I am experimenting with a autocomplete search-box that sends out an array after you submit the form. You can type multiple names and search for all of them.</p>
  
  <p>What I'm trying to do is to take that array in mootools, send it to PHP and display the results without leaving the page.</p>
  
  <p><a href="http://nightlifebratislava.com/demos/autocomplete/index.html" rel="nofollow">Here is the original file</a></p>
  
  <pre><code>// Autocomplete initialization
  var t4 = new TextboxList('form_tags_input_3', {unique: true, plugins: {autocomplete: {}}});
  
  // sample data loading with json, but can be jsonp, local, etc. 
  // the only requirement is that you call setValues with an array of this format:
  // [
  //  [id, bit_plaintext (on which search is performed), bit_html (optional, otherwise plain_text is used), autocomplete_html (html for the item displayed in the autocomplete suggestions dropdown)]
  // ]
  // read autocomplete.php for a JSON response example
  
  t4.container.addClass('textboxlist-loading');               
  new Request.JSON({url: 'autocomplete.php', onSuccess: function(r) {
    t4.plugins['autocomplete'].setValues(r);
    t4.container.removeClass('textboxlist-loading');
  }}).send();     
  </code></pre>
  
  <p>Here's autocomplete.php</p>
  
  <pre><code>$response = array();
  $names = array('Some name', 'Some name 2', 'etc');
  
  // make sure they're sorted alphabetically, for binary search tests
  sort($names);
  
  foreach ($names as $i =&gt; $name)
  {
      $filename = str_replace(' ', '', strtolower($name));
      $response[] = array($i, $name, null, '&lt;img src="images/'. $filename . (file_exists('images/' . $filename . '.jpg') ? '.jpg' : '.png') .'" /&gt; ' . $name);
  }
  
  header('Content-type: application/json');
  echo json_encode($response);
  </code></pre>
  
  <p>Submit.php</p>
  
  <pre><code>&lt;?php
  print_r($_POST);
  ?&gt;
  </code></pre>
  
  <p><a href="http://nightlifebratislava.com/demos/autocomplete/index2.php" rel="nofollow">And here is what I did</a></p>
  
  <p>My php:</p>
  
  <pre><code>&lt;?php
  $result['msg'] = print_r($_POST);
  
  echo json_encode($result);
  ?&gt;
  </code></pre>
  
  <p>And here are the changes I made in the index2.php file:</p>
  
  <pre><code>&lt;input type="submit" name="submitform" value="Submit" id="submitform" /&gt;
  &lt;p id="response"&gt;&lt;/p&gt;  
  
  $('#submitform').addEvent('click', function(){
  
    new Request.JSON({  
          url: "inc/php/json.php",  
          onSuccess: function(response){  
  
          $('response').set('html',+data.result);  
  
          }  
      }).get($('findnames')); 
  
  
  });
  </code></pre>
  
  <p>When you press submit, nothing happens, so obviously I made an error somewhere that I can't seem to figure out. </p>