How can a reset button in a PHP form be used to clear all fields without requiring users to refill the form?

When a reset button is clicked in a PHP form, it typically clears all fields and requires users to refill the form. To prevent this, you can use JavaScript to clear the form fields without requiring users to refill the form. By adding an onclick event to the reset button that calls a JavaScript function to clear the form fields, you can achieve this functionality.

<form method="post" action="submit.php">
  <input type="text" name="name" placeholder="Name"><br>
  <input type="email" name="email" placeholder="Email"><br>
  <input type="reset" value="Reset" onclick="clearFormFields()"><br>
  <input type="submit" value="Submit">
</form>

<script>
  function clearFormFields() {
    document.querySelector("form").reset();
  }
</script>