What potential security risks are associated with using $_SERVER['PHP_SELF'] in form actions in PHP?

Using $_SERVER['PHP_SELF'] in form actions can lead to potential security risks such as cross-site scripting (XSS) attacks and form spoofing. To mitigate these risks, it is recommended to use htmlspecialchars() function to sanitize the value of $_SERVER['PHP_SELF'] before using it in form actions.

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