What are the potential pitfalls of using $_SERVER['PHP_SELF'] in PHP forms?

Using $_SERVER['PHP_SELF'] in PHP forms can potentially expose your application to cross-site scripting (XSS) attacks. To mitigate this risk, it is recommended to use htmlspecialchars() function to escape the output of $_SERVER['PHP_SELF'] before using it in the form action attribute. This will prevent malicious users from injecting harmful scripts into your form.

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