How can PHP_SELF be used effectively in form actions to avoid issues with GET parameters being cut off?

When using PHP_SELF in form actions, GET parameters can be cut off if the URL contains query parameters. To avoid this issue, you can use htmlspecialchars() function to escape the special characters in the PHP_SELF value, ensuring that the URL is properly formed.

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  <!-- form fields go here -->
</form>