How can the issue of a new window opening with reg.php instead of the same window be resolved in PHP?

Issue: To prevent a new window from opening with reg.php, you can use JavaScript to submit the form within the same window instead of opening a new one. PHP code snippet:

<form id="registrationForm" action="reg.php" method="post">
  <!-- form fields here -->
  <input type="submit" value="Submit" onclick="submitForm()">
</form>

<script>
function submitForm() {
  document.getElementById('registrationForm').submit();
}
</script>