SOLVED

Has anyone got form.showErrorMessage to work?

Go to solution
Anonymous
Not applicable

Has anyone got form.showErrorMessage to work?

I'm trying to implement custom validation on my embedded Marketo Form 2.0.  We're strictly B2B and so I am wanting to add some additional validation to the Email field - to ensure they aren't using typical ISP/ free email accounts.  I have tried setting the field type to String (rather than email) and setting/ emptying the Custom Validation message (I'd rather avoid this as the message will change according to logic in the javascript), but whatever I do the error message is not populated from my code:

form.onValidate(function(){
    var vals = form.getValues();
    if (jqff.inArray(vals.Email, invalidEmailDomains) > -1 ){
       console.log("invalid email");  //triggers OK
       form.submitable(false);
       var TextField_Email = form.getFormElem().find("#Email");
       console.log(TextField_Email); //gets the field OK
       form.showErrorMessage("Custom error message here", TextField_Email);
}

TIA
Ben
 
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Have you seen example #9 on this page:

http://developers.marketo.com/documentation/websites/forms-2-0#examples

I would follow that example. Replace vals.Country to vals.Email, and then use regex to match non-business emails. 

Let me know if that makes sense?

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Have you seen example #9 on this page:

http://developers.marketo.com/documentation/websites/forms-2-0#examples

I would follow that example. Replace vals.Country to vals.Email, and then use regex to match non-business emails. 

Let me know if that makes sense?
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Hi Murtza,
This is based on that example - hence the use of form.onValidate() and var vals = form.getValues();  My question is why is this line:

  form.showErrorMessage("Custom error message here", TextField_Email);

...not working?  As the comments in my code state - the error condition is being triggered and the variable TextField_Email is selected OK, but the validation message is not getting set to the string I am passing ("Custom error message here") its just displaying what is set in the form field's settings.

BTW jqff is just jQuery in noconflicts mode so don't let that confuse anyone...
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Also whoever marked this as solved it isn't please remove the Solved flag.  Thanks
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Looks like Enget Dang's done it - although I don't quiet see the difference to what I've got... will test & confirm...
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

Ben - Can you please post a link to your test page, or on JSfiddle? It would help to see code in context to figure out what's going on. 
Anonymous
Not applicable

Re: Has anyone got form.showErrorMessage to work?

For what it is worth, we are trying to do the same thing.  We are able to get the error message to show

var emailElem = form.getFormElem().find("#Email");
...{other logic, such as setting correct error_msg}...
 form.showErrorMessage(error_msg, emailElem);

----------
However, we have a different issue.  When the user clicks the submit button, everything works great - the error message is shown and the form is not submitted.  When user hits the Enter key instead, the form is not submitted but the error message shows briefly and then disappears.

It seems that ENTER is causing the form to reset, and thus prevents the error message from persisting. 

Any ideas on how to keep the error message persisting if a user clicks ENTER instead of clicking the submit button?