Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kris Janssen 210 posts 569 karma points c-trib
    Jan 14, 2014 @ 00:22
    Kris Janssen
    0

    Dropdown pre values from Querystring

    Hi guys,

    I have a seemingly simple problem for which the solution somehow eludes me completely.

    Say I have a general purpose form where users can vote on a select number of options (using radiobuttons).

    Instead of hard coding the options (prevalues), I want to inject them, depending on the page from which the form is linked.

    The form will get called as such:

    ../myfrom.aspx?options=option1,option2,option3,option4

    I thought I could access QueryString from HttpContext in my custom pre value source and just populate pre values from there by splitting the string but this does not really work. No error but no result either.

    Anybody know how to achieve this?

    Cheers,

    Kris

  • Kris Janssen 210 posts 569 karma points c-trib
    Jan 14, 2014 @ 11:10
    Kris Janssen
    100

    Turns out it was actually working on the published form.

    I used this code to achieve it (rudimentary but can be fancied significantly:

    public override List<PreValue> GetPreValues(Field field)
        {
            List<PreValue> _lResult = new List<PreValue>();
    
            try
            {
                string[] strings = HttpContext.Current.Request.QueryString["edates"].Split(',');
                int sort = 0;
                foreach (string value in strings)
                {
                    PreValue _pvPreVal = new PreValue();
                    _pvPreVal.Id = sort;
                    _pvPreVal.Value = value;
                    _pvPreVal.SortOrder = sort;
                    _lResult.Add(_pvPreVal);
                    sort++;
    
                }
            }
            catch (Exception ex)
            {
                Umbraco.Forms.Data.LogHelper.Error(
                    "Get values fromrequest provider: " + ex.ToString());
            }
    
            return _lResult;
        }
    

    In the backend, this doesn't generate actual pre values, not even if I add things to the URL.

    However, in the live form, this works as expected and a list of checkboxes will get populated correctly.

    Maybe this is of use to some people...

Please Sign in or register to post replies

Write your reply to:

Draft