Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Episerver forms - form element validation using data from other form fields

Vote:
 

Hi,

I'd like to create a custom form element with validation, so that validation checks other values from the same form.

Is it possible to read data from other fields during element validation? If so, how can I access the data?

Thanks in advance!

#180818
Jul 27, 2017 12:38
Vote:
 

Hi,

Yes, you can read other fields data during element validation. Example:

var submitData = HttpContext.Current.Request.HttpMethod == "POST" ? HttpContext.Current.Request.Form : HttpContext.Current.Request.QueryString;

then you can get a specific element value by using: submitData["__field_123"]. The __field_123 is element name, you can get element name from element content link via extension method: 

public static string GetElementName(this ContentReference elementLink)
{
    return string.Format("{0}{1}", Constants.ElementIdPrefix, elementLink);
}

/DT

#180830
Jul 28, 2017 5:06
Vote:
 

Thanks a lot, I got it working.

/Mikko

#180831
Jul 28, 2017 8:25
Vote:
 

Add my 2cents, the (internal) extension has already existed in 

namespace EPiServer.Forms.Helpers.Internal

static class FormsExtensions

public static string GetElementName(this ContentReference elementLink)

#180956
Aug 03, 2017 5:20
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.