• Resolved yellowhippo

    (@yellowhippo)


    I’d like to be able to print an array of fieldset results in a single line, comma separated format like the following:

    (fieldname1),(fieldname2),(fieldname3)

    which would print something like:

    Value1,Value2,Value3

    Is this possible?

    • This topic was modified 6 years, 7 months ago by yellowhippo.
    • This topic was modified 6 years, 7 months ago by yellowhippo.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @yellowhippo,

    You simply should concatenate the fields’ names and the comma symbols, as follows:

    
    fieldname1+','+fieldname2+','+fieldname3
    

    Best regards.

    Thread Starter yellowhippo

    (@yellowhippo)

    Hello,

    Thank you for the quick reply. This works, but is there a way for the commas not to show if the fieldname is empty? I’m using checkboxes, so for example if I have fieldnames but only fieldset1 and fieldset4 have been selected, my result looks like:

    Value1,,,Value4

    Plugin Author codepeople

    (@codepeople)

    Hello @yellowhippo,

    There are multiple alternatives, one of them would be:

    
    (function(){
    var values = [];
    if(fieldname1) values.push(fieldname1);
    if(fieldname2) values.push(fieldname2);
    if(fieldname3) values.push(fieldname3);
    return values.join(',');
    })()
    

    Best regards.

    Thread Starter yellowhippo

    (@yellowhippo)

    Thank you again. This is still printing commas without a selected value. Are you able to provide an alternative? I’m sorry my coding is not good.

    Plugin Author codepeople

    (@codepeople)

    Hello @yellowhippo,

    Please, send me the URL to the webpage where the form is inserted for checking it in detail.

    Best regards.

    Thread Starter yellowhippo

    (@yellowhippo)

    The URL is: https://www.theenergymix.com/custom-rss/

    I’ve password protected the page – password is {7xQuh

    You will see I am trying to create a custom RSS feed with a category array at the end of the URL. You’ll notice the commas that are meant to separate the fieldnames appear before a selection is made.

    The code I’m using is

    (function(){
    var values = [];
    if(fieldname14) values.push(fieldname14);
    if(fieldname11) values.push(fieldname11);
    if(fieldname7) values.push(fieldname7);
    return values.join(',');
    })()

    Thank you again for your help.

    Plugin Author codepeople

    (@codepeople)

    Hello @yellowhippo,

    The issue is simple, as you’ve configured the checkbox fields with attribute: “Merge ticked up options” unticked, the equation should be edited as follows:

    
    (function(){
    var values = [];
    if(fieldname14.length) values.push(fieldname14);
    if(fieldname11.length) values.push(fieldname11);
    if(fieldname7.length) values.push(fieldname7);
    return values.join(',');
    })()
    

    Best regards.

    Thread Starter yellowhippo

    (@yellowhippo)

    Yes, that appears to work!

    Thank you again for the great support.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Print a comma separated list of fieldset values’ is closed to new replies.