Prefill form field with querystring value
Hi there,
I have a Sitefinity form on a page and like to fill one of its fields via querystring, I am new to Sitefinity 4x, please tell me how to do it?
Thanks,
Hello Zubair,
You can get a form with the following code and then fill its textbox:
var manager = FormsManager.GetManager();
var form = manager.GetFormByName(
"sf_test"
).SetValue(
"FormTextBox"
,
"Bla"
);
manager.SaveChanges();
Greetings,
Jen Peleva
the Telerik team
Hello,
This would come pre-filled all the time with the same value.
How about having a smaller form that takes you to a bigger one (Made by the Form Builder) and that bigger one loads populated with what has been given on the small one?
Is this scenario doable? Would the small form send GET or POST data?
Thank you.
Regards, Taha
Hi,
Actually this scenario is not supported.
We could provide you with some code snippet with which you could pre-populate the values in the forms:
protected
override
void
Render(HtmlTextWriter writer)
if
(!
this
.IsDesignMode())
var fieldControl =
this
.FieldControls.SingleOrDefault(fc => fc.MetaField.FieldName ==
"FormTextBox_0"
)
as
FieldControl;
if
(fieldControl !=
null
)
fieldControl.Value =
"FormTextBox_0"
;
fieldControl =
this
.FieldControls.SingleOrDefault(fc => fc.MetaField.FieldName ==
"FormTextBox"
)
as
FieldControl;
if
(fieldControl !=
null
)
fieldControl.Value =
"FormTextBox"
;
base
.Render(writer);