Let editor select form in page type

Justin L asked on June 27, 2017 15:19

Hello Kentico guru's,

For a project i'm working on, i'm trying to create a Page type in which the editor can select a form (which has been created with the forms application). I have the feeling that i am really close to achieving what i want, but the last bit is not working.

I've added a dropdown-list field to my Page type which uses SQL to get the available forms (select FormID, FormName from cms_form). So far its working and the editor can select the right form. But now i want to render the selected form in my transformation and thats where i'm stuck. Through the q&a section over here i've found out the following code which i can use to retrieve the form:

<cms:BizForm runat="server" ID="BizForm" FormName="FormName" EnableViewState="false" />

This works great when i enter a name value manually, but when i try to use the field from my page type (make it dynamic), like this:

<cms:BizForm runat="server" ID="BizForm" FormName='<%# Eval("fieldFromPagetype") %>' EnableViewState="false" />

The form is being rendered empty, like so:

<div id="p_lt_ctl04_pageplaceholder_p_lt_ctl05_UniversalViewer_uniView_ctl02_ctl00_BizForm"></div>

When i output <%# Eval("fieldFromPagetype") %>i do get the right form name, and if i copy/past it manually the form works great. I also tried to convert it .ToString(), but to no avail.

How can i render out the form dynamically? Please help :)

Best regards, Justin

Correct Answer

Trevor Fayas answered on June 27, 2017 17:05

Here's what i have for a client site that i do a dynamic form, i also do a BizForm.SiteName but shouldn't be needed unless you want to pull in a form from another site.

<cms:BizForm runat="server" ID="BizForm" Visible="false"/>
<script runat="server">
    protected override void OnInit(EventArgs e)
        {
            BizForm.Visible = true;
            BizForm.FormName= Eval<string>("fieldFromPageType");
            BizForm.ReloadData();
         }
</script>
1 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on June 27, 2017 15:54 (last edited on June 27, 2017 15:55)

You can use a <script runat="server"> tag to accomplish this.

<cms:BizForm runat="server" ID="BizForm" FormName="FormName" EnableViewState="false" />
<script runat="server">
    protected override void OnInit(EventArgs e)
        {
            BizForm.FormName= Eval<string>("fieldFromPageType");
         }
</script>

http://devtrev.com/Trev-Tips-(Blog)/May-2017/Transformation-ASCX-or-Text-XML

0 votesVote for this answer Mark as a Correct answer

Justin L answered on June 27, 2017 16:19 (last edited on June 27, 2017 16:20)

Hi Trevor Fayas, thank you for your reply. When trying out your snippet, i get an error saying: Required form 'FormName' does not exist. If i completely remove the FormName="FormName" from the first line of your snippet, the result is the same empty div as before:

<div id="p_lt_ctl04_pageplaceholder_p_lt_ctl05_UniversalViewer_uniView_ctl02_ctl00_BizForm"></div>

Am i doing something wrong?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 27, 2017 16:45

Try the below, StopProcessing tells the bizform to not even attempt to render, and the OnInit will set the FormName and tell it to processes.

<cms:BizForm runat="server" ID="BizForm"  StopProcessing="true"  EnableViewState="false" />
<script runat="server">
    protected override void OnInit(EventArgs e)
        {
            BizForm.StopProcessing = false;
            BizForm.FormName= Eval<string>("fieldFromPageType");
         }
</script>
0 votesVote for this answer Mark as a Correct answer

Justin L answered on June 27, 2017 16:56 (last edited on June 27, 2017 17:05)

Unfortunately this returns a new error: [TempITemplate.Template]: The 'StopProcessing' property cannot be set declaratively.

(Edit: I am using Kentico 10 by the way)

0 votesVote for this answer Mark as a Correct answer

Justin L answered on June 27, 2017 17:08

Awesome! Thank you for your help Trevor Fayas, the last snippet works like a charm!

0 votesVote for this answer Mark as a Correct answer

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