What are the potential security risks associated with using $_SERVER['PHP_SELF'] in a form action attribute?

Using $_SERVER['PHP_SELF'] in a form action attribute can lead to potential security risks such as cross-site scripting (XSS) attacks. To mitigate this risk, it is recommended to use htmlspecialchars() function to escape any special characters in the URL before using it in the form action attribute.

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