Hello Everyone
I am trying to make some of my php scripts reusable by saving them in a separate file on the server.
/public_html/scripts/phpfunctions.php
<?php echo 'This function has been called' ?>
And I have my HTML form
<form action="scripts/phpfunctions.php" method="post">
<input type="text" name="user_input">
<button type="submit">Submit</button>
</form>
Now that the function is a separate file it navigates the browser to that file instead of executing the script in my current file.
Normally I would solve this with AJAX and call the php function instead of a php page.
Is it possible to call a php function from inside a php script after pressing the submit button (the way it would normally execute in a page like the one below)
<!DOCTYPE html>
<head><title>No Title</title></head>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
echo 'function has been called'
}
?>
<body>
<form action="index.php" method="post">
<input type="text" name="user_input">
<button type="submit">Submit</button>
</form>
</body>
</html>