1

I have a Sitecore form with an email field and dropdown fields.

I want to populate the dropdown field values as soon as the user enters an email. An ajax call will be made to check the email against a third party database and get all the details for that email.

The values of the dropdowns need to be set based on the response received from the ajax call made when the email is entered.

How can this be achieved?

1 Answer 1

1

For this, you need to create a custom control. See how it will work.

  1. Create a custom control that will be a clone of the OOTB Email control.
  2. In the cshtml, you need to call Ajax by getting the email ID field, and then when a user enters the email address it will get the details and then fill the dropdown list or other controls on document.ready.

I have created something like this to create a custom cascade drop-down list that can help you to create your control. You can refer the code and the ajax functions using it.

How to create cascading droplist for Sitecore Form

Some useful links.

https://doc.sitecore.com/xp/en/developers/90/sitecore-experience-manager/walkthrough--creating-a-custom-form-element.html

4
  • In this way all fileds need to be custom control. As there are other fileds also like name address that also needs to be populated based on email added by user.
    – kartik
    Commented Jul 14, 2023 at 13:58
  • No I don't think that you need to create all custom control. You can add the JS code on one of your custom control like Custom Email and then on document.ready you will be able to get all the fields and you can populate those values. Commented Jul 14, 2023 at 14:06
  • Can u pls share more details on adding js to cutom control of email, and populating other field values.
    – kartik
    Commented Jul 17, 2023 at 3:08
  • If you will check the link I shared in answer. sitecore.stackexchange.com/questions/26633/… I have written an AJAX to get the data and then I am populating another dropdown value. So Like this you can get your other fields on the form and set values. Commented Jul 17, 2023 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.