Precompile a field of a Bizform with querystring

Sandro Rizzetto asked on May 7, 2018 15:07

How can I pre-compile a field of a bizform with a value? ASPX Template

<cms:WebPartContainer ID="wpcpageplaceholder" runat="server" ContainerName="Padding.Content">
<cms:BizForm runat="server" ID="BizForm" FormName="Contacts" EnableViewState="false" />
</cms:WebPartContainer>

Codebehind (where ? Page_Load is enough or Page_Init ?)

if (Request.QueryString != null && !String.IsNullOrEmpty(Request.QueryString["subj"]))
{
    // BizForm....  = Request.QueryString["subj"]    // pseudo code
}

Thanks in advance

Correct Answer

Dragoljub Ilic answered on May 8, 2018 10:54

Hi Sandro,

You should try everything the same, but use this event:

OnOnBeforeDataLoad="BizForm_OnBeforeDataLoad"

That will allow you to change data before is loaded into the biz form.

Also, as an additional approach, you can create custom macro expression (note: this is for k10), add all logic there and then just call it from form field as default value.

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dragoljub Ilic answered on May 7, 2018 15:27 (last edited on May 7, 2018 15:28)

Hi Sandro,

Did you tried to add macro expression as default value in the field where you want to add value from query string? In Forms -> Your Form -> Fields -> Default value, and for default value put something like this:

{% subj %}

or

{% QueryString.subj %}

That will add value from query string into your field where you want it.

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

Sandro Rizzetto answered on May 7, 2018 16:21

That would be a great suggestion; unfortunately I have to do some test and some concatenation (if blah, && bla bla..) before to get the right subject. So my question practically is how can I access a field from the .cs code

thanks

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on May 7, 2018 16:48 (last edited on May 7, 2018 16:50)

0 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on May 7, 2018 16:52 (last edited on May 7, 2018 16:52)

Hi Sandro,

In that case, you can use something like this, to update value on 'pre save' event for form: <cms:BizForm runat="server" ID="BizForm" FormName="Contacts" EnableViewState="false" OnOnBeforeSave="BizForm_OnBeforeSave"/>

And in code behind to have something like this:

protected void BizForm_OnBeforeSave(object sender, EventArgs e)
{
    var currentItem = ((CMS.OnlineForms.Web.UI.BizForm)sender).Data as NameOfYourBizFormItem;

    if (currentItem != null)
    {
        currentItem.NameOfTheField = "dummy text change";
    }
}

To have this class 'NameOfYourBizFormItem' available, you must generate code for your biz form, from Code tab.

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

Sandro Rizzetto answered on May 8, 2018 10:28

Dragoliub, that's works perfectly, but I want to show the subject in the textbox, so OnBeforeSave is too late. I tried with OnLoad and OnInit method of the form, but the field remains blank

(see https://www.dropbox.com/s/m1yf4cnw7cfcolb/bizform.png?dl=0)

0 votesVote for this answer Mark as a Correct answer

Sandro Rizzetto answered on May 8, 2018 12:15

Yeahh.. Thanks A LOT Dragoljub works perfectly.

0 votesVote for this answer Mark as a Correct answer

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