<?php
ob_start();
include("includes/checkerfun.php");
$errmsg= "";
#address
#postal_address
#office_phone_number
#tin
#email

function formChecker(){
       if(isset($_POST['save'])){

            if(empty(test_input($_POST['comp_name']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Company Name is Required!</p>";
            }elseif
            (empty(test_input($_POST['RC_num']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>RC Number is Required!</p>";
            }elseif
            (!is_numeric(($_POST['RC_num']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>RC Number must be Number!</p>";
            }elseif
            (empty(test_input($_POST['incorporation_date']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Date is Required!</p>";
            }elseif
            (empty(test_input($_POST['address']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Contact-Address is Required!</p>";
            }elseif
            (empty(test_input($_POST['postal_address']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Postal-Address is Required!</p>";
            }elseif
            (empty(test_input($_POST['office_phone_number']))){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Office Contact is Required and Must be Number</p>";
            }elseif
            (empty(test_input($_POST['tin'])) || !is_numeric($_POST['tin'])){
               $errmsg = "<p class='alert alert-danger text-center mt-3'>TIN is Required and Must be Number</p>";
            }elseif
            (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
               $errmsg = "<p class='alert alert-danger text-center mt-3'>Email is Required and Must be Valid</p>";
            }else{
               echo $errmsg =  "<div class='alert alert-success text-center mt-3'>Saved Successfully!</div>";
                     header('Refresh:5, url=register_form.php');
                     exit();  
            }

       }elseif(isset($_POST['save_and_continue']))
       {
           if(empty(test_input($_POST['comp_name']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Company Name is Required!</p>";
         }elseif
         (empty(test_input($_POST['RC_num']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>RC Number is Required!</p>";
         }elseif
         (!is_numeric(($_POST['RC_num']))){
             $errmsg = "<p class='alert alert-danger text-center mt-3'>RC Number must be Number!</p>";
         }elseif
         (empty(test_input($_POST['incorporation_date']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Date is Required!</p>";
         }elseif
         (empty(test_input($_POST['address']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Contact-Address is Required!</p>";
         }elseif
         (empty(test_input($_POST['postal_address']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Postal-Address is Required!</p>";
         }elseif
         (empty(test_input($_POST['office_phone_number']))){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Office Contact is Required and Must be Number</p>";
         }elseif
         (empty(test_input($_POST['tin'])) || !is_numeric($_POST['tin'])){
            $errmsg = "<p class='alert alert-danger text-center mt-3'>TIN is Required and Must be Number</p>";
         }elseif
         (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errmsg = "<p class='alert alert-danger text-center mt-3'>Email is Required and Must be Valid</p>";
         }else{
            echo $errmsg = "<div class='alert alert-success text-center mt-3'>Saved Successfully!</div>";
               header('Refresh:5, url=register_form002.php');
               exit();         
         }

         
       }

    return $errmsg;
}
ob_end_flush();
