Contact Page Validation on Text feild

Ravi_Ansal2
Level 6

Contact Page Validation on Text feild

I want if somebody fill out Contact Us page and if the Inquery i.e is a text feild contains Job Enquiries it filters out? Please help with any solutions
Tags (1)
3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Contact Page Validation on Text feild

That's a pretty specific text string.  I doubt you'll really catch every variation that way; a warning ("Employment applications or questions are not accepted via this form under any circumstances. Go here instead.") is likely better.

If you really want to match that strictly:

<script>MktoForms2.loadForm("//app-aa00.marketo.com", "XXX-YYY-ZZZ", 999,
    function(form) {   
  form.onValidate(function(){
    // Check a sample condition
    if(/job (e|i)nquir/i.test(form.vals().yourQuestion)){
      //prevent form submission
      form.submittable(false);
      form.showErrorMessage("Sounds like you want a job, which is not what this form is for.")
    }else{
      //enable submission for those who met the criteria.
      form.submittable(true);
    }
    })
    });
</script>
Rachit_Puri2
Level 7

Re: Contact Page Validation on Text feild

I tried to build something similar in past life but removed it later. Here's a use case: If a user comes to your contact form and fills in Job Inquiry in the description field, you can throw an error. In this case, he might slightly change the text and may succeed in filling out the form.
So, I allowed my users to fill in anything they wanted and then create a filter in MKTO
- Filter 1: If Solution contains 'job inquiry'
- Filter 2: If Solution contains 'job'
- Filter 3: If Solution contains 'inquiry'

Advanced filters: 1 or (2 and 3)
This was more effective in preventing the bad data, as I simply deleted these leads using a flow step.
SanfordWhiteman
Level 10 - Community Moderator

Re: Contact Page Validation on Text feild

@Rachit There's no reason to allow the form to post at all, then. You can still filter client-side (which is WAY easier with regular expressions than trying to build filters in the Mkto UI *shudder*).  Just discard the form data if you don't like it.  Don't bother telling the user you didn't actually post it. 

This code will skip the post if a bad value is found, but the user will still see the same Thank You text as if the post went through:

    form.onSubmit(function(form){
        if ( /(e|i)nquiry/.test(form.getValues().LastName) ) {
          form.submittable(false);
          this.onSuccess();
        }
    });
    form.onSuccess(function(form,thankYouURL){
        this.formElem[0].innerHTML = 'Thank you for submitting.';
        return false;
    });

Of course if we had control over the remote server, we would duplicate the exact same regex on the server to catch people who maliciously bypassed the validation. But we don't have that capability with Marketo as it is (I bet you don't recheck phone # formats in a Mkto filter, right?) so it's not like it just started to be a problem.

Bottom line, people can force whatever data they want onto the wire, and you'll never catch all the bad stuff on the server with Marketo's filtering syntax, so client-side validate-and-discard is the first and most flexible line of defense against such things.