PHP验证 - 输入类型“text”值必须是一个特定的单词

I am very sorry if this seems like a "Sigh, another one of those~" questions, but I've looked far and wide, yet none of the things seemed to suit my needs. I've looked at games like hangman, but they did it letter for letter and I couldn't figure out what to do with the code. (incompetence on my side, I admit. My knowledge is quite limited)

I then decided to look at quizzes, but they seemed to only deal with radio buttons. I've tried to edit scripts so that they had input type text boxes, but that seemed to lead to a lot more problems, seeing as I turned the question from multiple choice to open answer.

All I really want, is a basic setup like this:

Question
Input box
Button (submit, I think?)

Nothing fancy aesthetically-wise, just those three things.

Summary: How do I get my code to check if the answer they've given to the question is, for example, banana? And how do I get the button to -only- work if the word is indeed banana?

I'm very lost after several days of searching now. Many thanks for any effort you guys put into this, it'd mean a lot to me.

This is some basic client-side scripting using javascript.

Using the onkeyup event, we can test the value of what the user is typing in the text box, compare it to the "correct" value and enable/disable our submit button based on that evaluation.

<div id="question">How do you spell "banana"?</div><br />
<form action="" method="post">
    <input type="text" name="answer" id="answer" /><br />
    <input type="submit" id="submit" disabled="true" />
</form>

<script type="text/javascript" language="javascript">
    $("#answer").on('keyup', function() { 
        if ($(this).val() == "banana") {
            $("#submit").removeAttr("disabled");
        } else {
            $("#submit").attr("disabled", "true");
        }
    });
</script>

As others have pointed out, you'll want to verify the input on the server-side, just in case the user is a jerk and has disabled javascript.

<?php

    if ($_POST['answer'] == "banana") {
        // we're OK, do something
    } else {
        // return to the form and let the user know he's a cheater!
    }

basically you would change the submit button to a normal button, and run a javascript function to check if the value is correct before submitting the form. Something like:

<script>
    function validate() {
        if (document.getElementById('check_value').value == 'banana') {
            document.getElementById('myForm').submit();
        }
        else {
            alert("Incorrect value.");
        }
    }
</script>
<form id='myForm' method='POST' action='process.php'>
    <input type='text' id='check_value' />
    <input type='button' value='Submit' onclick='validate();' />
</form>

Hope that helps.