How to run a PHP function from an HTML form?

To run a PHP function from an HTML form, you will need to create an HTML form with the desired inputs, such as text fields and submit buttons. Then, you will need to create a PHP script that handles the form submission and runs the desired function.

Here is an example of a simple HTML form:

<form action="submit.php" method="post">
  <label for="input">Input:</label>
  <input type="text" id="input" name="input">
  <input type="submit" value="Submit">
</form>

The action attribute of the form element specifies the PHP script that will handle the form submission, and the method attribute specifies that the form data should be sent using the HTTP POST method.

Watch a course Learn object oriented PHP

In the PHP script submit.php, you can access the form data using the $_POST superglobal array and run the desired function:

<?php
  $input = $_POST["input"];
  myFunction($input);
?>

You need to make sure that the function is defined before it is called , otherwise you will get a fatal error .