title: Adding custom PHP to Wordpress page
body: <p>I have a small name generator script I am trying to add to my Wordpress website. The script itself works fine, I just don't know how to display it correctly.</p>
  
  <p>It's a simple select form - the user selects a character race and a number of names to generate, and the script pulls from various text files and spits out the names. (Here's a live demo: <a href="http://muthaoithcreations.com/name2.php" rel="nofollow">http://muthaoithcreations.com/name2.php</a>)</p>
  
  <pre><code>&lt;?php
  
  if(isset($_POST['submit']) &amp;&amp; !empty($_POST['race']) &amp;&amp; !empty($_POST['number'])) // after submitting and all fields are filled, this gets ran and the form below disappears
  {
    $race = $_POST['race'];
    $number = $_POST['number'];
  
    echo "&lt;p&gt;You asked for $number $race name(s):&lt;/p&gt;";
  
  $first = explode("\n", file_get_contents($race.'first.txt'));
  $middle = explode ("\n", file_get_contents($race.'middle.txt'));
  $last = explode("\n", file_get_contents($race.'last.txt'));
  $first2 = explode("\n", file_get_contents($race.'first.txt'));
  $last2 = explode("\n", file_get_contents($race.'last.txt'));
  
  shuffle($first);
  shuffle($middle);
  shuffle($last);
  shuffle($first2);
  shuffle($last2);
  
  if ($race == "Horc") { 
      for ($i = 0; $i &lt; $number; $i++) {
      echo $first[$i] . $last[$i] . ' ' . $first2[$i] . $last2[$i] . "&lt;br /&gt;\n"; }
  } elseif ($race == "Tiznt") {
      for ($i = 0; $i &lt; $number; $i++) {  
      echo $first[$i] . $middle[$i] . $last[$i] . "&lt;br /&gt;\n"; }
  } else {    
      for ($i = 0; $i &lt; $number; $i++) {  
      echo $first[$i] . $last[$i] . "&lt;br /&gt;\n"; }
  }
  
  echo '&lt;p&gt;&lt;input type="button" onclick="history.back();" value="Go Back and Try Again!"&gt;&lt;/p&gt;';
  
  }
  
  else // when the page loads, this else clause gets ran first
  {
  
    echo '&lt;p style="color:red;"&gt;Please choose your options.&lt;/p&gt;';
  ?&gt;
  &lt;form action="name2.php" method="post"&gt;
  &lt;label for="race"&gt;Select Charater Race:&lt;/label&gt;
  &lt;select name="race" id="race" /&gt;
  &lt;option value="Oofo" selected&gt;Oofo&lt;/option&gt;
  &lt;option value="Tiznt"&gt;Tizn't&lt;/option&gt;
  &lt;option value="Werm"&gt;Werm&lt;/option&gt;
  &lt;option value="Horc"&gt;Horc&lt;/option&gt;
  &lt;/select&gt;
  &lt;label for="number"&gt;Names to Generate:&lt;/label&gt;
  &lt;select name="number" id="number" /&gt;
  &lt;option value="1" selected&gt;1&lt;/option&gt;
  &lt;option value="5"&gt;5&lt;/option&gt;
  &lt;option value="10"&gt;10&lt;/option&gt;
  &lt;option value="20"&gt;20&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="submit" name="submit" value="Give Me Names!"/&gt;
  &lt;/form&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>If I put the generator code into a Page Template and then create a new page using the template, the form displays correctly, but when the user submits the form:</p>
  
  <blockquote>
    <p>Fatal error: Call to undefined function get_header() in /home/content/09/10184409/html/namegen-page.php on line 7</p>
  </blockquote>
  
  <p>(The file namegen-page.php is my template file, which is in my theme directory... it appears it's trying to find it in my root directory.)</p>
  
  <p>Do I need to have the form on a different page than the generator? Do I need to use a Wordpress plugin to display the PHP?
  I'm fairly new to Wordpress, and I'm not sure what I'm doing wrong. Any help is appreciated!</p>