Prefill form field with querystring value

Posted by Community Admin on 04-Aug-2018 13:44

Prefill form field with querystring value

All Replies

Posted by Community Admin on 26-Jan-2012 00:00

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,

Posted by Community Admin on 26-Jan-2012 00:00

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
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 13-Dec-2013 00:00

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

Posted by Community Admin on 17-Dec-2013 00:00

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);
        

You could add your custom logic to use it for getting and setting the values in the form.

All the best,
Nikolay Dimitrov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed