PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

populate a list using a shortcode goes wrong when item includes a comma

  1. [gravityforms id='3' field_values='title=mytitle&list=only 1 list item, except it has a comma so it's seen as 2' title='false']

    Above example will output my form with two items:
    - only 1 list item
    - except it has a comma so it's seem as 2

    However I want it as 1 item. How?

    The ' in it's was giving a problem as well, however I fixed this using urlencode. Unfortunately this doesn't fix the comma problem

    Posted 11 years ago on Thursday May 16, 2013 | Permalink
  2. I can't really find where this is handled in the gravity forms code, however my guess is that the comma separated list is first run through urldecode as a whole, and then split into individual items to fill the input fields in the form.

    By first doing the urldecode the comma's in the text are decoded and will be messing things up.

    If this is the case a fix would be easy by just switching the order in the code, first splitting the items and then do the urldecoding per item.

    I hope this helps in some way.

    Posted 11 years ago on Friday May 17, 2013 | Permalink
  3. David Peralty

    Hi there, I'll let our developers know about this today.

    Posted 11 years ago on Friday May 17, 2013 | Permalink
  4. Thanks David! I'll be awaiting their reply.

    Posted 11 years ago on Friday May 17, 2013 | Permalink
  5. Yea, this does seem to be a limitation of using the shortcode + a comma delimited list of values. The solution would be to url encode the comma, but the problem is that the shortcode processing from WordPress decodes the string when parsing the shortcode parameters.
    I think the only solution here is to use the gform_field_value_$parameter-name PHP hook to populate the list field (http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name). The following code snippet should do the trick. Place it in your theme's functions.php file.

    add_filter("gform_field_value_list", "populate_list");
    function populate_list($value){
       return array("row 1 - col1","row 1 - col2", "row 1 - col3",
                    "row 2 - col1", "row 2 - col2", "row 2 - col3",
                    "row 3 - col1", "row 3 - col2", "row 3 - col3");
    
    }
    Posted 11 years ago on Tuesday May 21, 2013 | Permalink
  6. Thanks for your reply Alex but I don't think this is a workable solution for my case.

    For each form I've made a page template which loads the filled out form using ajax when clicked on a piece of text (instant/live text editing). Therefor I have no way of knowing which text I have to feed the hook you're suggesting in my functions.php.

    As this only occurs with a comma character I've now fixed it using a simple comma replace in the text before I feed it to the shortcode, and then replace it back to a comma on the page using jquery. Not very pretty but it works.

    Posted 11 years ago on Wednesday May 22, 2013 | Permalink

This topic has been resolved and has been closed to new replies.