Hello everybody
I am trying to make some of my php scripts multiple by storing them in a separate file on the server.
/public_html/scripts/phpfunctions.php
<?php echo 'This function has been called' ?>
And I have an 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 translates the browser into this file instead of running the script in my current file.
Normally I would solve this using AJAX and call the php function instead of the php page.
Is it possible to call the php function from within the php script after clicking the submit button (the way it would normally be done on 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>
Trent source
share