Recent searches


No recent searches

New Request Page: Match validation based off 2 custom fields

Answered


Posted Oct 02, 2021

Hi All!

I'm surprised no one has asked this before - a simple request with what I assume to be a complicated solution.

Scenario: An end user would like to update their email address, and we would like the end-user to enter their new email address twice (two separate custom fields) - this is to reduce the possibility of entry errors.

Problem: Is there a way to validate that the two custom fields match exactly?
I assume this could be coded through either JSscript or by setting regex validation in the second custom field.

Any and all help would be appreciated! 


0

2

2 comments

image avatar

Christopher Kennedy

Zendesk Developer Advocacy

Hi Patrick,

There isn't a native feature that will perform this validation.  But you can accomplish this with custom JS in your Help Center theme that checks the custom field values before form submission.  Here's a sample demonstrating the concept that you can use as a starting point:

//replace <ticket_field_id> with the ID of each custom ticket field

var newRequestSubmitButton = $(".request-form input[type=submit]"),
      customFieldOne = $("#request_custom_fields_<ticket_field_id>"),
      customFieldTwo = $("#request_custom_fields_<ticket_field_id>");

  newRequestSubmitButton.on("click", function(e) {

  //if the two fields' values match, allow form submission to proceed
    if(customFieldOne.val()===customFieldTwo.val()){
      return;
    }

    //otherwise, stop the submission
    e.preventDefault();

    //code to display an error message to the user

  });

Best,

1


Christopher Kennedy

Amazing, thank you!

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post