DeveloperRawan
DeveloperRawan

Reputation: 73

Kentico forms to insert to Localization file

I'm a web developer and I'm currently working with our CMS website using the latest Kentico. The site is already finished and is working fine. The problem I am having is that we are a growing company with only three developers with too much to do. The leaders of the company want to input data to our contact page without knowing any programming at all.

I created a simple form that works great, and added it to our administration page. The problem I'm having is to write the data I get from the form to our contacts table.

<table style='text-align:left;'>
  <tr>
    <td rowspan='5'>
      <img src='./Company/media/Images/Persons/test.jpg' />
    </td>
    <td rowspan=5 width='10px'></td>
    <td><br/></td>
  </tr>
  <tr>
    <td><b>Firstname Lastname</b></td>
  </tr>
  <tr>
    <td>Title</td>
  </tr>
  <tr>
    <td>555 - 000000</td>
  </tr>
  <tr>
    <td>[email protected]</td>
  <tr>
</table>

The table gets its data from a localization page with different languages.

The form has this data, is there any way too make a loop that gets all the persons from the data the form produces and adds it in like that?

Note: I haven't worked with Kentico before so I'm a beginner with the tool but I am not a beginner developer.

Upvotes: 0

Views: 118

Answers (1)

rocky
rocky

Reputation: 7696

Yes there is a way to do that. Please follow the documentation.

using CMS.OnlineForms;
using CMS.DataEngine;
using CMS.SiteProvider;
using CMS.Helpers;
 
...
 
// Gets the form info object
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("CodeNameOfYourForm", SiteContext.CurrentSiteID);
 
// Gets the class name
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
 
// Loads the form's data
ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(formClass.ClassName);
 
// Checks whether the form contains any records
if (!DataHelper.DataSourceIsEmpty(data))
{
    // Loops through the form's data records
    foreach (BizFormItem item in data)
    {
        string firstNameFieldValue = item.GetStringValue("FirstName", "");
        string lastNameFieldValue = item.GetStringValue("LastName", "");
 
        // Store the data to your contacts table
    }
}

If you want to store the records to your contacts table immediately after they're created please follow the documentation and bind a handler to the BizFormItemEvents.Insert.After event as described in the comments.

Upvotes: 1

Related Questions