+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Prefill form field with querystring value

Prefill form field with querystring value

4 posts, 0 answered
  1. Zubair
    Zubair avatar
    142 posts
    Registered:
    26 Dec 2007
    26 Jan 2012
    Link to this post
    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,
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    26 Jan 2012
    Link to this post
    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
  3. Taha Zouhair
    Taha Zouhair avatar
    10 posts
    Registered:
    22 Aug 2013
    13 Dec 2013
    Link to this post
    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
  4. Nikolay Dimitrov
    Nikolay Dimitrov avatar
    17 posts
    Registered:
    17 Oct 2016
    17 Dec 2013
    Link to this post
    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
4 posts, 0 answered