What are the advantages and disadvantages of using $_SERVER['SCRIPT_NAME'] in form actions in PHP?

Using $_SERVER['SCRIPT_NAME'] in form actions can be advantageous as it provides a dynamic way to reference the current script file, making the code more portable. However, it can also be a security risk as it exposes the file path to potential attackers. It's recommended to sanitize and validate the input to prevent any malicious activities.

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