kitkit kitkit - 5 months ago 19
PHP Question

Create a Form and Reuse Code

I have a current application in PHP and I've finished the application using procedural way of coding in PHP. I want to convert it into OOP way.

I wish to have some basic example of a better approach creating forms and using the same code again in other forms I will create using OOP pattern.

Thank you.

Answer

Pass your data from your HTML form to this file

Class Form
    {
      function __construct()
      {
        if(isset($_GET['form_register']))
        {
          $this->check_register_details();
        }

        if(isset($_GET['form_login']))
        {
          $this->check_login_details();
        }

      }

      function check_register_details()
      {
        //do something
      }


  function check_login_details()
  {
    //do something
  }

  function insert_into_db()
  {
   //do something
  }
}
Comments