title: PHP form submission using oop
body: <p>I need a little help understanding how to use OOP in PHP to perform form submission action.
  Task at hand...
  I am trying to learn how to write PHP code using OOP. So far I understand the general idea of classes, functions, calling functions, inheritance etc.</p>
  
  <p>I have created a simple project for practice that allows a user to search for a meal in a certain location. So far, I have a form with 2 <code>&lt;input&gt;</code> fields. Normally for form action, I would do <code>&lt;form action="actionFileName.php"&gt;</code> but now that I have a class with a function to process the form, what do I use for the action value?</p>
  
  <p>I thought of creating an instance of the class and calling the function that processes the form but I get a Object not found! page after I submit the form with the <code>echo</code> values from the <code>else</code> statements in <code>hungryClass.php</code> displaying in the address bar.</p>
  
  <p>how do I fix this? Thanks.</p>
  
  <p>What my code looks like:
  HTML Form</p>
  
  <pre><code>&lt;?php  require_once 'hungryClass.php';
    $newSearch = new hungryClass();
  ?&gt;
  &lt;form action="&lt;?php $newSearch-&gt;searchMeal();?&gt;" method="post" id="searchMealForm"&gt;
    &lt;input type="search" size="35" placeholder="What Food Are you looking for?" id="mealName" class="meal"/&gt;
    &lt;input type="search" placeholder="City Area" id="mealLocation" class="meal"&gt;
    &lt;input type="submit" value="Satisfy Me" id="findMeal" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Page to process form (hungryClass.php)</p>
  
  <pre><code>&lt;?php 
    require_once('dbConnect.php');
    class hungryClass{
  
         public function searchMeal(){
           //call connection function.
            $connect = new dbConnect();
  
           //validate input
           if(isset($_POST['mealName'])){
               $meal = $_POST['mealName'];
  
             //ensure value is a string.
             $cleanse_meal = filter_var($meal, FILTER_SANITIZE_STRING);
             echo $cleanse_meal;
          }
          else{
         echo "Please supply the meal you crave";
          }
  
        //validate location
         if(isset($_POST['mealLocation'])){
       $location = $_POST['mealLocation'];
  
           //validate and sanitize input. ensure value is a string.
      $cleanse_location = filter_var($location, FILTER_SANITIZE_STRING);
          echo $cleanse_location;
  
         }
         else{
       echo "Please supply a location";
         }
  </code></pre>
  
  <p>}</p>
  
  <p>Database class</p>
  
  <pre><code>&lt;?php
  
  class dbConnect{
  private $host = "localhost";
  private $user = "stacey";
  private $pass = "";
  private $db_name = "menu_finder";
  
  private $connect;
  //private static $dbInstance;
  
  public function __construct(){
      try{
          $this-&gt;connect = new mysqli($host, $user, $pass, $db_name);
          if(mysqli_connect_error()){
             die('connection error('.mysqli_connect_errno().')' . mysqli_connect_error());
          }
      }
  
      catch(Exception $e){
          echo $e-&gt;getMessage();
      }
  }
  </code></pre>
  
  <p>?></p>