Kentico Form Validation

Jason Levy asked on April 11, 2017 20:00

I am working on a form and I want to validate to ensure a drop-down list is not the default value when the form is submitted and to display error message. Can I do this with in the CMS or do I need to use javascript or macro to validate?

Correct Answer

Rui Wang answered on April 11, 2017 20:43

The simple way to do this is, use the the built-in validation like "value cannot be 1",

Then you can populate you list of options like the following, which the Default (Please select) will give you 1 for the value and it will be invalid.

1;Please select
value1;option 1
value2;option 2
value3;option 3
1 votesVote for this answer Unmark Correct answer

Recent Answers


Jason Levy answered on April 11, 2017 21:53

Rui,

Thanks for this. I've implemented your suggestion but I have one follow up. Where do I set the built-in validation rule?

Under validation in the field setting?

1 votesVote for this answer Mark as a Correct answer

Rui Wang answered on April 11, 2017 22:00 (last edited on April 11, 2017 22:24)

Yes, click the button to add a validation rule. Something like this. Also be sure to check the field as required (toward the top of the properties).

Image Text

0 votesVote for this answer Mark as a Correct answer

Jason Levy answered on April 12, 2017 17:06

Rui, this solution works perfectly for me. I look forward to playing with more of the build in rules and eventually creating some of my own.

0 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on March 2, 2018 01:11

Hi, I applied this and it does seem to work, however the error message does not appear. I set both the default and error message on the rule, but none work. I also tried them separately but no luck.

Any advice on getting the error message to work will be appreciated.

0 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on March 2, 2018 01:33

Found the solution, layout did not contain a validation tag.

1 votesVote for this answer Mark as a Correct answer

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