Making BizForm fields inactive after submitting
When using a BizForm for collecting data you may need to have the fields displayed after the form is submitted, but the fields have to be disabled - not editable but the values are visible.
Here are the instructions how to achieve this goal for web part and inline control as well:
1. Please make a copy of your BizForm webpart as it is described here -
Modifying the code of standard web parts. Let's assume that you have
BizFormNew ID for your BizForm control.
2. Please find the
'SetupControl' method and change it following way (with text in bold):
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do nothing
}
else
{
// Set BizForm properties
BizFormNew.FormName = this.BizFormName;
BizFormNew.SiteName = this.SiteName;
BizFormNew.UseColonBehindLabel = this.UseColonBehindLabel;
BizFormNew.OnAfterSave += new BizForm.OnAfterSaveEventHandler(BizFormNew_OnAfterSave);
}
}
3. Now please add
'BizFormNew_OnAfterSave' method and add following code:
void BizFormNew_OnAfterSave()
{
if (BizFormNew.BasicForm != null)
{
// Go through form controls and disable them
foreach (DictionaryEntry entry in BizFormNew.BasicForm.FieldControls)
{
Control ctrl = entry.Value as Control;
if (ctrl is TextBox)
(ctrl as TextBox).Enabled = false;
}
if (ctrl is DropDownList)
(ctrl as DropDownList).Enabled = false;
(ctrl as ListBox).Enabled = false;
// add other field types if necessary
}
// Disable submit button if used
if (BizFormNew.BasicForm.SubmitButton != null)
BizFormNew.BasicForm.SubmitButton.Visible = false;
// Disable image button if used
if (BizFormNew.BasicForm.SubmitImageButton != null)
BizFormNew.BasicForm.SubmitImageButton.Visible = false;
// Stop bizform processing
this.BizFormNew.StopProcessing = true;
// Display a message via label
Label infoLabel = ((Label)(this.BizFormNew.FindControl("lblInfoLabel")));
infoLabel.Text = ResHelper.GetString("general.changessaved");
infoLabel.Visible = true;
}
}
}
4. Please note that if you use another input types within your BizForm you may need to add other decision statements in foreach cycle.
5. Please select '
Continue editing' option in:
CMS Desk -> Tools -> BizForms -> Edit -> General tab.
6. Your BizForm fields will be disabled for editing after BizForm was submitted.
7. Please note that the instruction above can be applied on BizForm webpart. If you wish to use it as an inline control please modify '
~\CMSInlineControls\BizFormControl.ascx.cs' file and add there the same code as you would add into webpart.
8. Since the BizForm has stopped processing now the notification e-mails are not sent. If you still wish to send them we would recommend you to send the confirmation and notification e-mails by API in your
OnAfterSave method. The sample code of sending e-mails is here:
www.kentico.com/docs/devguide/modifying_the_code_of_standard_web_parts.htm
The Notification and Confirmation e-mail template (and other details from your settings of Notification and Confirmation e-mails) is stored in the class:
CMS.FormEngine.BizFormInfo
See also: API ReferenceApplies to: Kentico CMS 3.x