Forms

Avinash P asked on August 16, 2016 08:11

We have forms located on various pages on our site. We would like the user to fill out their zip code of this form. On the notification email, we'd like to automatically populate the city and state based off of the zip code the user provided. Would this be possible?

Correct Answer

Roman Hutnyk answered on August 16, 2016 08:48

Sure. You can add city and state fields to a form and make them hidden (they can not be required). Then implement custom handler for form item insert before, where you can get zip and call some service, that will return you address details, so you could store them into form fields. No need to save a form, system will handle this.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Avinash P answered on August 16, 2016 09:30

Thanks for the answer. I am new to kentico , i don't know how to create the custom handler for specific form . i have multiple forms ,i don't need all the forms use custom handler.

Thank you in advance for any help, Avinash

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on August 16, 2016 09:52 (last edited on August 16, 2016 10:10)

I would recommend to use the BizFormItemEvents.Insert.After event because it gets executed after the form is successfully inserted.

You can register event like: (see docs for more information)

BizFormItemEvents.Insert.After += Insert_After;

And then you can send out e-mail using the data from the inserted form like (the form is filtered as well using the ClassName which is unique to each form):

private void Insert_After(object sender, BizFormItemEventArgs e)
{
    // filter only your particular form
    if (e.Item.ClassName.Equals("bizform.yourFormClassName", StringComparison.OrdinalIgnoreCase))
    {
        // get data from form
        var zip = e.Item.GetStringValue("ZipColumnName", "");

        // do something with zip or any other field

        // send e-mail using Kentico API
        var email = new EmailMessage()
        {
            Recipients = "to@local",
            From = "from@local",
            Subject = "Subject",
            Body = "Your Html e-mail",
            PlainTextBody = "Plain text body"
        };

        EmailSender.SendEmail(email);   // additionally you can use E-mail template so that you can edit the template in Kentico administration area
    }
}
0 votesVote for this answer Mark as a Correct answer

Avinash P answered on August 16, 2016 11:24

Thanks for answer, But i want to set the field(custom) values before insertion of form.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 16, 2016 14:41

I believe you're looking for v7 information, please check out your post I answered here.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.