How can I make a POST Request from Custom File? (v2021)

Hello All,
I am porting a PHPMaker 2019 project to PHPMaker 2021. I have already defined my custom classes and I can call them in the custom file. However, I need to save data to the DB from the custom file via a form but submitting the form only refreshes the page. I will appreciate any help on how to fix this.

You may post your code in that Custom Files for more discussion. In addition, did you enable Include common files option for your Custom File?

Thanks for your response. Here is what I did. First, I defined a custom class and stored in the /models folder. I am able to call this Class and some methods from different custom files easily. Here is the content of the custom Helpers class.

namespace PHPMaker2021\hrgeniee2;
use mysqli;

class Helpers
{
	public $db;
	public function __construct()
	{
		$this->db = new mysqli('localhost', DBU, DBP, DBN);
	}

	public function getUserProfile()
	{
		return mysqli_fetch_array(mysqli_query($this->db, "SELECT *  FROM app_users WHERE a.user_id = " . CurrentUserID()), MYSQLI_ASSOC);
	}

	public function clockIn(array $form)
	{
		$lat = $form["lat"];		$longt = $form["longt"];		$emp_id = $form["emp_id"];		$opco = $form["opco"];

		$sql = mysqli_query($this->db, "INSERT INTO attendance(lat, longt, emp_id, country, month_period, entry_type, clockin_area, source) 
				VALUES('$lat', '$longt', $emp_id, '$opco', DATE_FORMAT(date,'%b %Y'),'Manual ClockIn', 'On Site', 'Dashboard')");
		if ($sql) {
			$last_id = mysqli_insert_id($this->db);
			echo "User $emp_id clocked in at successful at " . time();
			return $last_id;
		}
		$flag = false;
		echo "result1 failed " . mysqli_error($this->db) . "<br> $sql";
		return false;
	}
}

I am able to call (new Helpers())->getUserProfile() successfully from custom file that handles form submission. But when I try to trigger the clockIn method on form submission, nothing happens; the page only gets reloaded. Here is what I have in my custom file that handles form submission:

namespace PHPMaker2021\hrgeniee2;

// Page object
$Staffdashboard = &$Page;

$helpers = new Helpers();
$profile = $helpers->getUserProfile();  //This works perfectly 

//I tried this first
if (isset($_POST['opco'])) {
    $helpers->clockIn($_POST);
}

//Then I tried this
if ($_SERVER['REQUEST_METHOD'] == "post") {
    $helpers->clockIn($_POST);
}

var_dump($_POST) //
?>
<div class="col-4">
    <div class='clockin'>
        <img src='images/icon2.svg' />
    </div>
    <form method="post" action="https://localhost/nuhrg/staffdashboard">
        <input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
        <input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
        <input type="hidden" name="lat" id="lat" required>
        <input type="hidden" name="longt" id="longt" required>
        <input type="hidden" name="emp_id" id="emp_id" value=<?php echo $profile['user_id'] ?> required>
        <input type="hidden" name="opco" id="opco" value=<?php echo $profile['opco'] ?> required>
        <button type="submit" name="submit" class="btn btn-primary btn-lg btn-block">Clock In! </button>
    </form>
</div>
<script>
    $(document).ready(function() {
        var geo_options = {
            enableHighAccuracy: true,
            maximumAge: 60,
            timeout: 27000
        };
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showLocation);
        } else {
            $('#location').html('Geolocation is not supported by this browser.');
        }
    });
    function showLocation(position, geo_options) {
        var lat = position.coords.latitude;
        var longt = position.coords.longitude;
        document.getElementById("lat").value = lat;
        document.getElementById("longt").value = longt;
    }
</script>

You may try GET method instead of POST method.