Create forms

Form controls

To add controls programmatically to a form, you use the Telerik.Sitefinity.Modules.Forms.Web.UI.Fields namespace that contains all form controls. The form control classes are listed below:

  • FormTextBox

  • FormMultipleChoice

  • FormCheckboxes

  • FormParagraphTextBox

  • FormDropDownList

  • FormSectionHeader

  • FormInstructionalText

  • FormSubmitButton

Creating a form

To create a form, you must use the FormsManager class. In this example you create a form with a field for entering the name and aSubmit button. You use FormTextBox for the name text field and FormSubmitButton for the Submit button.

To create the form, perform the following:

  1. Create a form in Sitefinity CMS backend by pasting the following code:

  2. Create the controls for the example form and call the CreateForm method by pasting the following code:

In CreateForm, first, you get the FormsManager and verify that the form is not yet created. You edit and check out the form. Then, you add the controls to the form draft by wrapping them in FormDraftControl. You use siblingId to keep the last control in the placeholder where the current control must be placed in. Finally, you check in and publish the form.

In CreateContactForm, first, you set the name, title and success message for the form. Then, you create the name field and the Submitbutton. Once created, you add the controls in a dictionary with the name of the placeholder where they must be placed in. Finally, you callCreateForm to create the form in Sitefinity CMS backend.

Was this article helpful?

Next article

Query forms