Best Approach to open existing online BizForm item in edit mode and update

jayraj datta asked on March 15, 2017 15:06

Hi There,

I've created a single form to maintain email/newsletter subscription. I would like, to provide a unsubscription url like "/unsubscription?Email=test@test.test". Which will show previous subscription details. Then while submitting form will update the details.

I've gone through several articles. there could be two possible solution on this.

1) Customize C# code for InsertAfter Event. Since I want to keep last updated record, so I need to add code to delete previous record of emailId.

2) Customize SetupControl method of SetBizform.ascx.cs. There need to provide ItemId will open the form in edit mode. on submit will update the existing record. Will not add a new record. // Get the biz form item, and set form control values var bizFormItem = BizFormItemProvider.GetItem(ItemID, className); if (bizFormItem != null) { // Set the item ID viewBiz.ItemID = bizFormItem.ItemID; }

I believe option 2 is better than option 1, but I also think we should not alter main kentico files. Please suggest on above.

Recent Answers


Brenden Kehren answered on March 15, 2017 15:16

Couple things with online forms and their data.

  1. The form itself has a definition that holds all the form info.
  2. Each form definition has form data.

So what you want to do is get the form data and provide a public way to update this data. What I would do is create a simple webpart which has a textbox and a button on it and when they enter a valid email address do a lookup in the form data using the api and compare the email provided with the email in the form data, if you find it, do an update to it. I'd not worry about the overhead of loading the form and all the other "stuff" with the form which can cause complications.

Your code might look like this:

CMS.OnlineForms.BizFormItem item = CMS.OnlineForms.BizFormItemProvider.GetItems("bizformitem.youritemname").WhereEquals("EmailField", txtFrom.Text.Trim);
if (item != null)
{
    item.Delete(); // or whatever you want to do
}
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 15, 2017 15:19

Firstly, indeed i would never alter main kentico files, if any adjustments need to be made clone it first and work off of the clone!

Onto the item at hand, i've seen what you are trying to do (where you can checkbox the things subscribed to or things you can possibly subscribe to), and check/uncheck and update.

One thing to ask is, i assume you currently have a Form (kentico Form) that a user fills out to 'subscribe,' once they hit submit how are you handling the form submission to subscribe them?

Honestly i would just create a custom web part that takes the user's email address, and uses kentico's API to make a checkbox list of possible subscriptions (and check ones they are subscribed to), and handle the "Update" button to see which subscriptions are checked/unchecked and make adjustments accordingly. As in most things, there will be some form of a joining table that you can update through the API.

But a lot depends on what custom logic you already need and how can it most cleanly be implemented and easy to maintain.

The reason i wouldn't do #1 is any change will require a recycle, and the logic can be done through a custom webpart instead. The custom events are great for tasks that need to occur when someone happens that you have little control over otherwise.

Can you explain a little more your processes, where is the subscription and what are you subscribing to?

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on March 15, 2017 15:21

I would just clone the Bizform webpart, add your logic to determine the itemid, set it, and then just use that cloned web part. No need to modify the existing control if you clone it.

0 votesVote for this answer Mark as a Correct answer

jayraj datta answered on March 16, 2017 08:59 (last edited on December 10, 2019 02:30)

Thanks to you all. I'm new to kentico, all this suggestions are good to explore my knowledge. It could be done in many ways, but I found making a clone of BizForm web part more efficient and easiest way. My scenario: I've three different Forms from where user can perform Rewards subscription. I need to maintain a common table/form to maintain subscription. There on Form Insert After event I added code to insert/update record in common Subscription Form. This way I'm maintaining a common form/table to store subscription details for a emailId. It was done earlier.

Now my goal was to give ensubscription write to user. I would have open the form using query string like "?EmailID=test.test.test", then adding macro in fields default value {% GlobalObjects.LOL_FS_Unsubscribe.Where("EmailID = '"+ QueryString.EmailId + "'").ItemsAsFields.OperationType |(identity)GlobalAdministrator%}. This will open the form with existing records. Then again can change selection and submit the form. It has a draw back, as it'll add a new row to form. For that I would have to remove the previous row, from form insert after event.

But I was looking if there would be a way to open the form on Edit mode, and on submitting the form will update the form, instead of adding a new row. So as I mention above option 2 was doing that, but have done that on a clone. So, it's good now.

thanks, jayraj

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.