Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > How to set a hidden field in a biz form? View modes: 
User avatar
Member
Member
steven4733-gmail - 2/3/2012 4:24:24 PM
   
How to set a hidden field in a biz form?
Could anyone tell me how to set a hidden field and it's value in a biz form? Thank you.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/5/2012 6:15:55 AM
   
RE:How to set a hidden field in a biz form?
Hello.

Can you clarify some particular scenario, as it depends when exactly you want to to that? You could use macro expression within given field, or you can access any field in proper event handler, like OnBeforeSave() for example. You can find ore info here.

Best Regards,
Radek Macalik

User avatar
Member
Member
steven4733-gmail - 2/5/2012 10:30:03 PM
   
RE:How to set a hidden field in a biz form?
For each biz form, I have a paticular parameter that is set by system, not customer. I don't want to show the parameter to customer.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/18/2012 3:40:12 AM
   
RE:How to set a hidden field in a biz form?
Hello.

Ok, let me try to understand it. Do you have any default value in some BizForm’s field (this is how I understand your sentence "I have a particular parameter that is set by system”) and you want to show / hide this field on live site, according to current user’s name or role? Is that correct? If not, can you clarify? Thank you.

Best Regards,
Radek Macalik

User avatar
Member
Member
steven4733-gmail - 2/20/2012 11:56:06 AM
   
RE:How to set a hidden field in a biz form?
I expect to use url to pass the value of a parameter and I think I have to customize code of bizform. So I think my question could be understood as where can I customize bizform?

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/21/2012 2:29:45 AM
   
RE:How to set a hidden field in a biz form?
Hello.

I am not quite sure you answered my previous question, so I will keep it in what you wrote me. You have some parameter in URL and you want to process it somehow in your BizForm. In this case, all available customization possibilities for BizForms are described here, including links within that chapter.

Best Regards,
Radek Macalik

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 2/21/2012 11:35:58 AM
   
RE:How to set a hidden field in a biz form?
Use global Event handlers to do this. I have done exactly what you have described.

Miro pointed me to this page for reference:

http://devnet.kentico.com/docs/devguide/event_handlers_overview.htm

In your App_Code/samples/modules folder there is a file named SampleClassLoaderModuleAttribute where you can add code similar to this:


private class SampleClassLoaderModuleLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Initializes the module
/// </summary>
public override void Init()
{

ObjectEvents.Insert.After +=new EventHandler<ObjectEventArgs>(Insert_After);
}
public void Insert_After(object sender, ObjectEventArgs e)
{

if (e.Object.ObjectType.ToLower() == "bizformitem.bizform.yourformcodename")
{
e.Object.SetValue("YourHiddenField", HttpContext.Current.Request.QueryString["yourparametername"]);
e.Object.Update();

}

}



You can also create your own class as long as it inherits from CMSLoaderAttribute

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/22/2012 8:20:16 AM
   
RE:How to set a hidden field in a biz form?
Hello.

Thank you for sharing your solution.

Best Regards,
Radek Macalik

User avatar
Member
Member
egarrison-wte - 10/1/2012 11:47:46 AM
   
RE:How to set a hidden field in a biz form?
I am trying this solution and I am getting an error from it. I am running 6.0.46. Is the logic different under 6.x?

Here is the error I get:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'HttpContext' does not exist in the current context

Source Error:


Line 30:             if (e.Object.ObjectType.ToLower() == "bizformitem.bizform.form2")
Line 31: {
Line 32: e.Object.SetValue("validation", HttpContext.Current.Request.QueryString["validation"]);
Line 33: e.Object.Update();
Line 34:

Source File: c:\websites\kentico6_dev3\App_Code\Samples\Modules\SampleClassLoaderModule.cs Line: 32

User avatar
Member
Member
egarrison-wte - 10/2/2012 1:47:56 PM
   
RE:How to set a hidden field in a biz form?
I am going to answer my own post so the next guy who's head is not on right, doesn't have the issue.

Top of that file add the USING statements:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;

using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.SettingsProvider;
using CMS.DataEngine;
using CMS.EventLog;
using CMS.SiteProvider;
using CMS.PortalEngine;
using CMS.FormEngine;
using CMS.IO;
using CMS.URLRewritingEngine;

using CMS.WorkflowEngine;


Then you will have the code as:


public override void Init()
{
{
// -- This line provides the ability to register the classes via web.config cms.extensibility section from App_Code
ClassHelper.OnGetCustomClass += ClassHelper_OnGetCustomClass;
}

{

ObjectEvents.Insert.After +=new EventHandler<ObjectEventArgs>(Insert_After);
}
}
public void Insert_After(object sender, ObjectEventArgs e)
{

if (e.Object.ObjectType.ToLower() == "bizformitem.bizform.form2")
{
e.Object.SetValue("formvalue", HttpContext.Current.Request.QueryString["value"]);
e.Object.Update();

}



User avatar
Member
Member
jeremiah.bayles-vinsolutions - 2/11/2013 2:49:13 PM
   
RE:How to set a hidden field in a biz form?
I'm trying to understand if this same concept would work to set the style sheet attribute, display: none. so that I would actually have a hidden field. Did you add your field to the form with the Kentico GUI and set visible conditions to always be false?

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/28/2013 1:41:42 PM
   
RE:How to set a hidden field in a biz form?
Hello.

In general, you can hide a field via CSS or disabling the "Visible" property either in GUI, or in the code.

Best Regards,
Radek Macalik