What are the potential security risks of relying on JavaScript for user input validation in a web application?

Relying solely on JavaScript for user input validation in a web application can pose security risks as it can easily be bypassed by users with malicious intent. To mitigate this risk, it is important to also validate user input on the server-side using a server-side language like PHP. This ensures that even if the client-side validation fails, the server-side validation will catch any malicious input before processing it.

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
    $input = $_POST["input"];

    // Server-side validation
    if(!empty($input)) {
        // Process the input
    } else {
        // Handle validation error
    }
}
?>