What are the potential pitfalls of using JavaScript for answer validation in PHP?

Using JavaScript for answer validation in PHP can lead to potential security risks, as client-side validation can be bypassed by users who disable JavaScript or manipulate the code. To ensure secure validation, it is recommended to perform server-side validation in PHP to validate user input before processing it.

<?php
// Server-side validation in PHP
if(isset($_POST['answer'])){
    $answer = $_POST['answer'];

    // Validate the answer here
    if($answer == 'correct'){
        echo 'Answer is correct!';
    } else {
        echo 'Answer is incorrect!';
    }
}
?>