I understand the name of this question is a little vague, not sure how to phrase it short enough but here is my question: I have a form, and at the end of the form I want to add an input that asks the user (for example) what 1 + 7 is, and the only accepted value can be 8 - except I want to use PHP to randomize the number between 2 and 9 on page load, how do I go about doing that?
Here is the input:
<label>What is $question?
<input type="text" id="human" placeholder="What is it?"></label>
The way I picture this I see two end variables, one being the question and the other being the answer. There would be a series of questions with the appropriate answers that would be shuffled on page load. Like 1+1, 1+2, 1+3, 4+4, 3+6, etc... and the PHP would have some fun with that in the background before a bot can determine what the value is.
I can sort of read PHP, I just don't know where to start when writing it. All help is appreciated!
Based on what you gave me for the above answer, this is what I've come up with for the alternate code I'm using here (it obviously doesn't work though haha):
EDIT: I actually got it working, you can view the working code below... but if you could take a look and polish it that would be awesome =)
<div>
<div><label id="question-label"><span data-tooltip class="has-tip tip-top" title="This is how we know you're actually human!" id="question-tip-f"><span id="question-f"></span>?</span> <span class="star">*</span></label></div>
<div><input type="text" id="human-f" placeholder="What is it?"></div>
</div>
<script>
var num1 = Math.floor( Math.random()*9 ) + 1,
num2 = Math.floor( Math.random()*9 ) + 1,
result = num1 + num2;
document.getElementById( 'question-f' ).innerHTML = num1 + ' + ' + num2;
document.getElementById( 'form-footer' ).addEventListener( 'submit', function(e) {
var el = document.getElementById( 'human-f' );
var ql = document.getElementById( 'question-tip-f' );
if ( el.value != result ) {
ql.parentNode.setAttribute( "class", 'error' );
e.preventDefault();
}
});
</script>