PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Number Masked Field Keeps Resetting Tablet Keyboard to Alpha

  1. Apologies if this has been asked/answered before but I was unable to find anything regarding this via search. I have a website at http://www.inspectionqc.com. The first field titled FHA Case # is masked to only accept numbers in the format ###-######. The end users will be filling in the form on tablets, and in testing on an ACER ICONIA TAB (Android OS) when the user sets the keyboard to number input, it resets to alpha after each character input. So they have to enter 9 digits, and hit the key to put the keyboard back to number input after each character. I realize this may be an OS issue, but is there any known workaround so the users can type the numbers in more quickly? Is there another field type I could use that might not show this behavior and still validate as ###-######?

    Thanks in advance for any help,

    Michael Griffin

    Posted 7 years ago on Tuesday September 4, 2012 | Permalink
  2. I don't have a tablet here to confirm your issue. Rather than force the input format with JavaScript using the input mask, you could use custom validation after form submission.

    http://www.gravityhelp.com/documentation/page/Gform_validation
    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook

    Posted 7 years ago on Tuesday September 4, 2012 | Permalink
  3. Thanks so much for the quick reply Chris! I understand the basics of the gform_validation_hook, but I am not sure how to test or what variable to test for. In other words, is there a way I can test for the format ###-###### or do I need to run a check on each character to verify that it is a number? And if the latter is true, would I check for the "-" character in the same way? I understand if this is beyond the scope of this support forum, but I figured it couldn't hurt to ask.

    Thanks again for any help/direction you can provide,

    Michael

    Posted 7 years ago on Tuesday September 4, 2012 | Permalink
  4. You would need a regular expression (regex) to determine if the format of the input is correct. It would ensure that there are 3 numbers, a dash, then 6 numbers. It's all done at once: the regexwill give the string a true or false (it's the correct format or it's not.) If it's not, return a validation error. If it is, continue with the submission.

    The regex for a string like your example might look something like this:

    \b\d{3}-\d{6}\b

    That's 3 digits, a hyphen, and 6 digits. The \b are word boundaries. I think you would use it like this in PHP (assuming field 2 in the form holds your FHA case number):

    [php]
    if (preg_match("/\d{3}-\d{6}/", $entry[2])) {
        echo "That's a valid case number.";
    } else {
        echo "That's an invalid case number.";
    }

    That is the regex part of it. You have to combine that with the gform_validation hook and return a validation error or not.

    Posted 7 years ago on Tuesday September 4, 2012 | Permalink
  5. Thanks so much Chris for the response. Apologies for not getting back sooner but this week has been crazy! I will try and implement your suggestion. I will have to do a little reading up on the gform_validation hook, but hopefully I can get it to work. It kills me with these tablets how some things work on one but not on the other. Seems like they all have at least one thing that doesn't work as expected!

    Thanks again!

    Michael

    Posted 7 years ago on Wednesday September 12, 2012 | Permalink
  6. Okay, so I pretty lost on how to code this. If this is outside the scope of this support forum I will completely understand, but below is the initial code I added to functions.php to try after changing the field to a standard text field. The field ID for the Case # is 1. Am I way off base here?

    add_filter('gform_validation', 'validate_casenumber');
    function validate_casenumber($validation_result){
    $form = $validation_result["form"];
    	if (preg_match("/\d{3}-\d{6}/", $entry[1])) {
    		$validation_result["is_valid"] = true;
    				} else {
    	if($field["id"] == "1"){
    		$field["failed_validation"] = true;
                    $field["validation_message"] = "This field is invalid!";
                    break;
    		            }
            }
    $validation_result["form"] = $form;
    return $validation_result;
    }
    Posted 7 years ago on Friday September 14, 2012 | Permalink
  7. I created a form with a single field to test this. Please try using different formats for the data you input and see if the validation is good: http://gravity.chrishajer.com/force-fha-case-number-format/

    This is the code: http://pastebin.com/ntptAp0L

    Posted 7 years ago on Saturday September 15, 2012 | Permalink
  8. Chris,
    I cannot thank you enough for your quick responses and help! That works perfectly with a standard text field. I will be combing through the code to better understand the variables you used so that I can learn from this and improve my understanding of php functions. The gravity forms plugin is overall extremely easy to use and very intuitive, and the level of support when I do run into a snag makes it worth every penny. Thanks again!

    Sincerely,
    Michael Griffin

    Posted 7 years ago on Sunday September 16, 2012 | Permalink
  9. Thanks Michael. Glad you were able to make that work.

    Posted 7 years ago on Sunday September 16, 2012 | Permalink

This topic has been resolved and has been closed to new replies.