2

I have a simple feedback form in a Kentico CMS site.

There are two inputs and a submit button. One of the inputs is a yes/no radio button selection and the other is a text area input. (please see screenshot).

I want the user to be able to submit the form only when at least one of the following 3 criteria are met:

  1. 'Was this page helpful?' was answered.
  2. The text area value is not blank and the value does not equal the default text value which is 'How can we improve this page? Providing feedback helps us to improve this information'
  3. Or, both criteria in 1 and 2 are met.

Basically, I want them to answer at least one of the inputs.

Is this type of validation possible using Kentico forms/online form web part?

Screenshot of form (may be of use): enter image description here

Doozer Blake
  • 7,677
  • 2
  • 29
  • 40
Dave Haigh
  • 4,369
  • 5
  • 34
  • 56
  • 1
    With their built-in form elements, no. You'd likely have to create a custom form control to do this, or use some other method of gathering the data. – Doozer Blake Jun 06 '12 at 23:55

1 Answers1

1

I contacted Kentico about this functionality and their response is below:

Regrettably, this type of validation is not provided. Kentico CMS perform validation for each built-in control separately.

In general, you have two options. The first one is to implement the OnBeforeValidate or OnAfterValidate events which give you the ability to perform a custom validation if necessary. You can access each field as follows:

string answerText = ValidationHelper.GetString(viewBiz.BasicForm.Data.GetValue("answerText"), "");

If the validation fails, you need to set the StopProcessing of the BizForm control to true:

viewBiz.StopProcessing = true;

More information about customization possibilities related to BizForm can be found here: http://devnet.kentico.com/docs/devguide/index.html?api_bizforms_customization_possibilities.htm

Another way would be creating a custom form control just as it is described in the documentation: http://devnet.kentico.com/docs/devguide/developing_form_controls.htm

The form control would allow users to specify both fields and therefore you can peform the custom validation (IsValid method) according to your requirements.

To set a field other than the field for which the for control is used, you need to implement the GetOtherValues method.

Then, just disable the other field so that it is not displayed on the form twice.

Dave Haigh
  • 4,369
  • 5
  • 34
  • 56