Try our conversational search powered by Generative AI!

Class XForm

Main class for the XForms functionality.

Inheritance
System.Object
XForm
Implements
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.XForms
Assembly: EPiServer.XForms.dll
Version: 7.19.2
Syntax
public class XForm : IItem
Remarks

This class holds the XForm and its metadata. It also provides the functionality to Load and save it to the datalayer. The form is stored as a serialized XML document on the form:

<root>
  <model> 
    <instance>
      [instance values] 
    </instance>
  </model>
  [Xform controls and HTML]
</root>

Examples

The contents of the sample XForm "Vote"

Constructors

XForm()

Declaration
public XForm()

Properties

AllowAnonymousPost

Indicates if the form requires login before it is able to post data for the form.

Declaration
public bool AllowAnonymousPost { get; set; }
Property Value
Type Description
System.Boolean

AllowMultiplePost

Indicates if the same user can post the form several times.

Declaration
public bool AllowMultiplePost { get; set; }
Property Value
Type Description
System.Boolean

Changed

The time the form was last changed.

Declaration
public DateTime Changed { get; set; }
Property Value
Type Description
System.DateTime

ChangedBy

The name of the user that last changed the form.

Declaration
public string ChangedBy { get; set; }
Property Value
Type Description
System.String

Created

The time that the form was created.

Declaration
public DateTime Created { get; set; }
Property Value
Type Description
System.DateTime

CreatedBy

The name of the user that created the form.

Declaration
public string CreatedBy { get; set; }
Property Value
Type Description
System.String

CustomUrl

An url that is used when sending form data with ChannelOptions.CustomUrl.

Declaration
public string CustomUrl { get; set; }
Property Value
Type Description
System.String

Document

The XForm is stored as a XML document with a syntax of a reduced set of the XForm standard. For more information about the XForm standard see http://www.w3.org/TR/2003/REC-xforms-20031014/.

Declaration
public SerializableXmlDocument Document { get; set; }
Property Value
Type Description
SerializableXmlDocument

XForm as a serializable XML document.

DocumentData

Declaration
protected string DocumentData { get; set; }
Property Value
Type Description
System.String

DocumentForTransfer

Used for import/export.

Declaration
public string DocumentForTransfer { get; set; }
Property Value
Type Description
System.String

Folder

The XFormFolder that the form should be saved in.

Declaration
public XFormFolder Folder { get; set; }
Property Value
Type Description
XFormFolder

FolderId

Gets or sets the id of the folder containing this XForm.

Declaration
public Identity FolderId { get; set; }
Property Value
Type Description
Identity

FormName

Gets or sets the public name of the XForm.

Declaration
public string FormName { get; set; }
Property Value
Type Description
System.String

The public name of the XForm.

Id

The unique identifier of the form as a Guid.

Declaration
public object Id { get; set; }
Property Value
Type Description
System.Object

A Guid.

Remarks

Although the return value is typed as an object the return value will always be a Guid.

InstanceRoot

A pointer to the XForm instance node.

Declaration
public XmlNode InstanceRoot { get; }
Property Value
Type Description
System.Xml.XmlNode

IsNull

Not used and will always return false.

Declaration
public bool IsNull { get; }
Property Value
Type Description
System.Boolean

IsSent

Indicates if form data has been sent for the form.

Declaration
public bool IsSent { get; set; }
Property Value
Type Description
System.Boolean

MailFrom

An e-mail address that is used for sending e-mail.

Declaration
public string MailFrom { get; set; }
Property Value
Type Description
System.String

MailSubject

A subject that is used for sending e-mail.

Declaration
public string MailSubject { get; set; }
Property Value
Type Description
System.String

MailTo

An e-mail address that is used for sending e-mail.

Declaration
public string MailTo { get; set; }
Property Value
Type Description
System.String

Model

A pointer to the XForm model node.

Declaration
public XmlNode Model { get; }
Property Value
Type Description
System.Xml.XmlNode

Name

Gets the Internal data layer name for the XForm.

Declaration
public string Name { get; }
Property Value
Type Description
System.String

PageAfterPost

Set this value to indicate that the user should be redirected to the following page after the form has been successfully posted.

Declaration
[Obsolete("This property is obsolete, use property PageGuidAfterPost instead.")]
public int PageAfterPost { get; set; }
Property Value
Type Description
System.Int32
Remarks

This property is obsolete, use property PageGuidAfterPost instead.

PageGuid

The guid of the page that the form is posted from.

Declaration
public Guid PageGuid { get; set; }
Property Value
Type Description
System.Guid
Remarks

This can be used when searching through form data.

PageGuidAfterPost

Set this value to indicate that the user should be redirected to the following page after the form has been successfully posted.

Declaration
public Guid PageGuidAfterPost { get; set; }
Property Value
Type Description
System.Guid

PageId

The page id that the form belongs to.

Declaration
[Obsolete("The PageId property is obsolete, use the PageGuid property instead", true)]
public int PageId { get; set; }
Property Value
Type Description
System.Int32

PostingUser

The name of the user that is posting the form.

Declaration
public string PostingUser { get; set; }
Property Value
Type Description
System.String

Methods

CreateFormData()

Creates a XFormData object from the Instance node in the XForm.

Declaration
public XFormData CreateFormData()
Returns
Type Description
XFormData

CreateHtmlFragments()

Parses the HTML part of the XForm and returns a collection of HTML fragments

Declaration
public IEnumerable<HtmlFragment> CreateHtmlFragments()
Returns
Type Description
System.Collections.Generic.IEnumerable<HtmlFragment>

CreateInstance()

Creates an empty XForm.

Declaration
public static XForm CreateInstance()
Returns
Type Description
XForm

Empty XForm.

CreateInstance(Guid)

Loads a XForm from the data layer.

Declaration
public static XForm CreateInstance(Guid formId)
Parameters
Type Name Description
System.Guid formId

Internal identifier of the XForm.

Returns
Type Description
XForm

Loaded XForm.

CreateInstance(Guid, Guid)

Loads an XForm from the data layer and fill it with loaded data.

Declaration
public static XForm CreateInstance(Guid formId, Guid xFormDataId)
Parameters
Type Name Description
System.Guid formId

Internal identifier of the XForm to load.

System.Guid xFormDataId

Internal identifier of the XFormData to load.

Returns
Type Description
XForm

Loaded XForm.

CreateInstanceInFolder(XFormFolder)

Creates an empty XForm and sets the Folder property to the folder argument.

Declaration
public static XForm CreateInstanceInFolder(XFormFolder folder)
Parameters
Type Name Description
XFormFolder folder

The folder that the XForm should be created in.

Returns
Type Description
XForm

Delete()

Deletes the form.

Declaration
[Obsolete("Use the static version for better performance")]
public void Delete()

Delete(Guid)

Delete the XForm identified by the formId

Declaration
public static void Delete(Guid formId)
Parameters
Type Name Description
System.Guid formId

The id of the XForm to delete

DeleteAllPostedData()

Deletes all posted data for the XForm.

Declaration
public void DeleteAllPostedData()

GetForms()

Get all XForms

Declaration
public static IList<XForm> GetForms()
Returns
Type Description
System.Collections.Generic.IList<XForm>

A collection of XForm objects

GetForms(Identity)

Get all XForms stored in the folder identified by folderId

Declaration
public static IList<XForm> GetForms(Identity folderId)
Parameters
Type Name Description
Identity folderId

The id of the folder to list XForms for

Returns
Type Description
System.Collections.Generic.IList<XForm>

A collection of XForm objects

GetForms(Identity, String, Int32, Int32, String, SortOrder, out Int32)

Get Selected XForms

Declaration
public static IList<XForm> GetForms(Identity folderId, string createdBy, int skip, int take, string orderBy, SortOrder sortOrder, out int count)
Parameters
Type Name Description
Identity folderId

The id of the folder to list XForms for. Null will return all folders

System.String createdBy

Get XForms created by user. String.Empty or null will not make an selection on 'createdby'

System.Int32 skip

Skip x number of items

System.Int32 take

Take x number of items

System.String orderBy

Order by selected column

System.Data.SqlClient.SortOrder sortOrder

Which order to sort

System.Int32 count

Returns the total number of items

Returns
Type Description
System.Collections.Generic.IList<XForm>

List of XForms containing maximum 'take' number of items

GetForms(String, Int32, Int32, String, SortOrder, out Int32)

Get Selected XForms

Declaration
public static IList<XForm> GetForms(string createdBy, int skip, int take, string orderBy, SortOrder sortOrder, out int count)
Parameters
Type Name Description
System.String createdBy

Get XForms created by user. String.Empty or null will not make an selection on 'createdby'

System.Int32 skip

Skip x number of items

System.Int32 take

Take x number of items

System.String orderBy

Order by selected column

System.Data.SqlClient.SortOrder sortOrder

Which order to sort

System.Int32 count

Returns the total number of items

Returns
Type Description
System.Collections.Generic.IList<XForm>

List of XForms containing maximum 'take' number of items

GetFormsCount(Identity)

Returns the number of XForms in the folder identified by folderId

Declaration
public static int GetFormsCount(Identity folderId)
Parameters
Type Name Description
Identity folderId

The id of the folder to count the number of XForms in

Returns
Type Description
System.Int32

The number of XForms in the folder

GetIndex(String, String, String, SortOrder)

Get the database index of an XForm item

Declaration
public static int GetIndex(string xFormId, string createdBy, string orderBy, SortOrder sortOrder)
Parameters
Type Name Description
System.String xFormId

The Id of the XForm item

System.String createdBy

Which user (username) the xForms must be created by. Use String.Empty or NULL to receive all

System.String orderBy

Order by selected column

System.Data.SqlClient.SortOrder sortOrder

Which order to sort

Returns
Type Description
System.Int32

The database index of the specified XForm item

GetIndex(String, String, String, SortOrder, Identity)

Get the database index of an XForm item

Declaration
public static int GetIndex(string xFormId, string createdBy, string orderBy, SortOrder sortOrder, Identity folderId)
Parameters
Type Name Description
System.String xFormId

The Id of the XForm item

System.String createdBy

Which user (username) the xForms must be created by. Use String.Empty or NULL to receive all

System.String orderBy

Order by selected column

System.Data.SqlClient.SortOrder sortOrder

Which order to sort

Identity folderId

Folder to search in. Use null to search for all folders

Returns
Type Description
System.Int32

The database index of the specified XForm item

GetInstanceNode(String)

Declaration
protected XmlNode GetInstanceNode(string key)
Parameters
Type Name Description
System.String key
Returns
Type Description
System.Xml.XmlNode

GetPostedData()

Get all data posted to the database for this form.

Declaration
public IList<XFormData> GetPostedData()
Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(DateTime, DateTime)

Get all data posted to the database for this form between the given dates.

Declaration
public IList<XFormData> GetPostedData(DateTime beginDate, DateTime endDate)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(DateTime, DateTime, Guid)

Get all data posted to the database for this form between the given dates for a certain page.

Declaration
public IList<XFormData> GetPostedData(DateTime beginDate, DateTime endDate, Guid pageGuid)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

System.Guid pageGuid

Only return posted data for this page. The parameter is ignored if it equals System.Guid.Empty.

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(DateTime, DateTime, Guid, Int32, Int32)

Get data posted to the database for this form between the given dates for a certain page.

Declaration
public IList<XFormData> GetPostedData(DateTime beginDate, DateTime endDate, Guid pageGuid, int skip, int take)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

System.Guid pageGuid

Only return posted data for this page. The parameter is ignored if it equals System.Guid.Empty.

System.Int32 skip

The number of posts to skip before reading

System.Int32 take

The number of posts to read

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(DateTime, DateTime, Int32, Int32)

Get data posted to the database for this form between the given dates.

Declaration
public IList<XFormData> GetPostedData(DateTime beginDate, DateTime endDate, int skip, int take)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

System.Int32 skip

The number of posts to skip before reading

System.Int32 take

The number of posts to read

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(Guid, DateTime, DateTime)

Get all data posted to the database for this form between the given dates for a certain page.

Declaration
[Obsolete("Use GetPostedData(DateTime beginDate, DateTime endDate, Guid pageGuid) overload instead", false)]
public IList<XFormData> GetPostedData(Guid pageGuid, DateTime beginDate, DateTime endDate)
Parameters
Type Name Description
System.Guid pageGuid

Only return posted data for this page. The parameter is ignored if it equals System.Guid.Empty.

System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedData(Int32, Int32)

Get data posted to the database for this form.

Declaration
public IList<XFormData> GetPostedData(int skip, int take)
Parameters
Type Name Description
System.Int32 skip

The number of posts to skip before reading

System.Int32 take

The number of posts to read

Returns
Type Description
System.Collections.Generic.IList<XFormData>

An IList containing XFormData objects

GetPostedDataCount()

Returns the number of posts for this form

Declaration
public int GetPostedDataCount()
Returns
Type Description
System.Int32

An integer

GetPostedDataCount(DateTime, DateTime)

Returns the number of posts for this form between the given dates.

Declaration
public int GetPostedDataCount(DateTime beginDate, DateTime endDate)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

Returns
Type Description
System.Int32

An integer

GetPostedDataCount(DateTime, DateTime, Guid)

Returns the number of posts for this form between the given dates for a certain page.

Declaration
public int GetPostedDataCount(DateTime beginDate, DateTime endDate, Guid pageGuid)
Parameters
Type Name Description
System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

System.Guid pageGuid

Only return posted data for this page. The parameter is ignored if it equals System.Guid.Empty.

Returns
Type Description
System.Int32

An integer

GetPostedDataStatistics(String, DateTime, DateTime, Guid)

Gets the statistics for the posted data for a specific form field.

Declaration
public IDictionary<string, int> GetPostedDataStatistics(string fieldName, DateTime beginDate, DateTime endDate, Guid pageGuid)
Parameters
Type Name Description
System.String fieldName

Name of the form field to get statistics for.

System.DateTime beginDate

The start date for the search. This will be ignored if set to DateTime.MinValue

System.DateTime endDate

The end date for the search. This will be ignored if set to DateTime.MinValue or DateTime.MaxValue

System.Guid pageGuid

Only return posted data for this page. The parameter is ignored if it equals System.Guid.Empty.

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, System.Int32>

An IDictionary with the form field option as the key and the number of votes for the given key as the value.

GetStore()

Returns the DynamicDataStore for the XForms definition store

Declaration
public static DynamicDataStore GetStore()
Returns
Type Description
DynamicDataStore

A DynamicDataStore instance or null if the store does not exist

InternalSave()

Declaration
protected void InternalSave()

MapPostsStore()

Declaration
protected void MapPostsStore()

Move(XFormFolder)

Declaration
public void Move(XFormFolder folder)
Parameters
Type Name Description
XFormFolder folder

Save()

Saves the form.

Declaration
public void Save()

SetInstanceData(String, String)

Sets a value to an instance variable. This can be used to set a default value for an input field .

Declaration
public void SetInstanceData(string key, string value)
Parameters
Type Name Description
System.String key

The name of the control.

System.String value

The value to set.

Events

TranslateEvent

Event that is triggered when a text should be translated.

Declaration
[Obsolete("Custom translations using a special event on XForms has been removed in favor of new localization services")]
public static event XForm.TranslateTextEventHandler TranslateEvent
Event Type
Type Description
XForm.TranslateTextEventHandler
Remarks

This is normally handled by EPiServer.

Implements

Extension Methods