Backend form validation | Community
Skip to main content
August 8, 2018
Solved

Backend form validation

  • August 8, 2018
  • 1 reply
  • 4198 views

Hi there,

I am building a landing page with a Marketo form on it to capture basic user data. In our own backend, we have a custom validation logic for email-addresses to filter out non-company emails and competitors. I am trying to use the Forms 2 API to do that for me, but I see no way to embed my own backend-call there, wait for it's result or then abort the submission. Setting the `Mkto.validateField`-function seems to have a similar issue, as it's a synchronous call and I can't wait for an asynchronous web request there. Any help would be appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

There are examples of this concept if you search the Community.

Use a boolean in a closure (outside form.validate() scope) to manage the overall valid/invalid state.

In form.validate(), set form.submittable(boolean_state).

In your callback function, on a positive result set boolean_state = true and call form.submit().

Not sure why you'd waste latency doing this on your back end, though. If it's just pattern matching, you can implement it in JS and increase responsiveness for the end user.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
August 8, 2018

There are examples of this concept if you search the Community.

Use a boolean in a closure (outside form.validate() scope) to manage the overall valid/invalid state.

In form.validate(), set form.submittable(boolean_state).

In your callback function, on a positive result set boolean_state = true and call form.submit().

Not sure why you'd waste latency doing this on your back end, though. If it's just pattern matching, you can implement it in JS and increase responsiveness for the end user.

August 9, 2018

Thank you, that did work. I do see how this is an overall ugly flow, but unfortunately I've got a business requirement to do the validation that way. It's more than just a pattern comparison, and we'd also not like to put a list of our "acknowledged" competitors into the public Javascript.

SanfordWhiteman
New Participant
August 9, 2018

and we'd also not like to put a list of our "acknowledged" competitors into the public Javascript.

Comparing hashes would take care of that.