How can the code snippet be modified to prevent the form from being submitted twice?

The issue of the form being submitted twice can be solved by disabling the submit button after it has been clicked to prevent multiple submissions. This can be achieved by adding a JavaScript function that disables the button upon click. By disabling the button, users will not be able to click it multiple times, ensuring that the form is only submitted once.

<form method="post" action="submit.php" onsubmit="disableButton()">
  <input type="text" name="name" placeholder="Name">
  <input type="email" name="email" placeholder="Email">
  <button type="submit" id="submitBtn">Submit</button>
</form>

<script>
  function disableButton() {
    document.getElementById('submitBtn').disabled = true;
  }
</script>