Skip to content

Instantly share code, notes, and snippets.

@contensis
Created July 30, 2014 14:03
Show Gist options
  • Save contensis/26fe5d2f1b66174e52ae to your computer and use it in GitHub Desktop.
Save contensis/26fe5d2f1b66174e52ae to your computer and use it in GitHub Desktop.
Code used to import data into the 'new' forms module in Contensis.
Option Strict On
Imports CMS_API
Imports Contensis.FormsModule.Controls
Module Module1
Sub Main()
' Initialise Contensis
CMS_API.initsettings("localhost")
PostForm()
End Sub
' Note: At this stage the only way of identifying the form element names is through using fiddler against your form, or viewing source on the rendered form webpage.
' Ideally run fiddler when submitting a form to see each of the name value items
' We will improve this in the future.
Private Sub PostForm()
' Fill in the version ID of your form
Dim FormVersionID As Integer = 36193
' Add the Data as appropriate to the name value collection one for each form element
Dim Data As New System.Collections.Specialized.NameValueCollection
' Example single line elements
Data.Add("ctrl_2_first-38039", "Derek")
Data.Add("ctrl_2_last-38039", "Trotter")
' See the examples below for specific form element types
'' Example checkbox item 1
'Data.Add("ctrl_2_0-36193", "Value 1")
'' Example checkbox item 2
'Data.Add("ctrl_2_1-36193", "Value 2")
'' Example checkbox item 3
'Data.Add("ctrl_2_2-36193", "Value 3")
'' Example name
'Data.Add("ctrl_3_first-36193", "First Name")
'Data.Add("ctrl_3_surname-36193", "Last Name")
'' Example address
'Data.Add("ctrl_4_street-36193", "Street")
'Data.Add("ctrl_4_address2-36193", "Address line 2")
'Data.Add("ctrl_4_city-36193", "City")
'Data.Add("ctrl_4_county-36193", "County")
'Data.Add("ctrl_4_postcode-36193", "Postcode")
'Data.Add("ctrl_4_country-36193", "Country")
'' Example time
'Data.Add("ctrl_5_hour-36193", "11")
'Data.Add("ctrl_5_minute-36193", "00")
'Data.Add("ctrl_5_seconds-36193", "00")
'Data.Add("ctrl_5_period-36193", "AM")
Dim IpAddress As String = "127.0.0.1"
' SourceAddress is the page from which the form posted
Dim SourceAddress As String = "http://www.mysite.co.uk/page1.aspx"
' Get the Form from the VersionID
Dim Form As Contensis.FormsModule.Controls.Form = Reporting.FormReportingService.GetFormFromVersionID(FormVersionID)
If Form IsNot Nothing Then
Try
' The final parameter is the PageContentID which hosts the form
' In this case 0 means that the form post came from the Form Preview screen
Contensis.FormsModule.Controls.Reporting.FormReportingService.CreateFormsPost(Data, Form, IpAddress, SourceAddress, 0)
Console.WriteLine("Data posted successfully.")
Console.ReadLine()
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.ReadLine()
Finally
Console.WriteLine("Press enter to exit...")
Console.ReadLine()
End Try
End If
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment