0

This question is related to a previous post, But I think mine is somehow different.

I'm trying to implement a sort of spam check with an image. I'm using a picture of a Callaway golf ball and asking what the brand is.

Is there a way to accept both capitalized, and lowercase answers? I'm trying to figure that out and I can't. I guess the real question is:

Can you accept two answers in the value?

The easy fix is to use an image or ask a question that doesn't involve capitalization, but I really want to use the golf ball thing.

Community
  • 1
  • 1

2 Answers2

1

If I'm understanding your question correctly, there is some one right answer, but the issue is that the client might enter the correct string, but using the wrong casing. Correct me if I'm wrong in understanding your question.

You can use javaScript to transform all answers to lower case and then compare the results. To transform a string to lowercase use .toLowerCase().

Here's a working example with a form:

<script>
    function checkForm() {
       var elem = document.getElementById('myInput');
       elem.value = elem.value.toLowerCase();
       return elem.value.length > 0;
    }
</script>
<form action="somewhere.php" method="POST" onSubmit="checkForm()">
    <input id="myInput" type="text">
    <button type="submit">Submit</button>
</form>

Ideally though, if there's a server side component to it you should do the lower case transformation there. Also note jQuery is not needed - this is just pure JS :)

winhowes
  • 7,845
  • 5
  • 28
  • 39
0

Just transform the value to all lowercase and you don't have to worry about caps.

If using jQuery:

var captcha = $('#captcha').val().toLowerCase();
if(captcha === 'callaway'){
  alert('We got a hole in one!');
}
charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • This also submits the form with the input empty. I'm not really good at jQuery, really just a copy and paste guy lol. – Brandon Jan 25 '16 at 01:18
  • sounds like you forgot name attributes. That's what browser uses to make the key for `key/value` pair Can't help much without any html in question – charlietfl Jan 25 '16 at 01:21
  • – Brandon Jan 25 '16 at 01:31
  • just like i suggested ... won't submit an input that doesn't have a name – charlietfl Jan 25 '16 at 01:33
  • Okay, so what should the input look like? What would the name be in relation to what i have in jQuery? - Thanks for the help. – Brandon Jan 25 '16 at 01:38
  • it's the match at the server receiving it that counts `name="anything"` – charlietfl Jan 25 '16 at 01:39
  • Would you mind making the code for this? I can't seem to get it to do what I need. I'm just making guesses now lol. – Brandon Jan 25 '16 at 01:44