SOLVED

How to change separation character in multi-selection form field

Go to solution
Candyce_Coving1
Level 2

How to change separation character in multi-selection form field

We have a multi-selection form field (in Forms 2.0). When the form is submitted, the separator character between the choices is a semi-colon. We need to make the separator be a different character. I've tried to use Javascript to update the field prior to the form submit but the concatenation with the semi-colon seems to happen after the form submit.

Any idea of how to transform the fields to convert the semicolon into the pipe [aka "|"] character?

Thanks for any ideas.
Sheila
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to change separation character in multi-selection form field

You have great instincts!  While there's nothing wrong with a separate multi-select and hidden string variable, that just makes more to manage.  I would catch the onSubmit event and then change the value to the new, |-delimited single value.  User never sees it, but it will be posted to the server like you want.

Demo here: http://jsfiddle.net/sanford/1cvgxwkb/

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: How to change separation character in multi-selection form field

A multiple-selection select will submit as an array (if more than one selection):

    fieldname[]=aaa&fieldname[]=bbb

or as a single string if only one selection:

    fieldname=ccc

Are you talking about the way the values are represented within Marketo? That's not the same as the submit.
Candyce_Coving1
Level 2

Re: How to change separation character in multi-selection form field

Hi Sanford,
It took me a while to figure out that the submit is an array. 🙂 

I am trying to change the way the resulting string is represented in Marketo. Instead of the ; I need the separation between them to be a |. I can't think of any way within Marketo to easily change the character.

Originally I thought I could change it with some javascript code before the submit, but as you pointed out, the way it is represented inside of Marketo.

So thinking out loud, it seems that I need to convert the array into a single string before the submit. I would probably have the visible field on the form be the multi-selection and then a hidden field that is a single string  to populate with proper concatenation. Would that work? I'm only learning Javascript so if you know how to do this off the top of your head, would you mind sharing?

Thank you!


 
SanfordWhiteman
Level 10 - Community Moderator

Re: How to change separation character in multi-selection form field

You have great instincts!  While there's nothing wrong with a separate multi-select and hidden string variable, that just makes more to manage.  I would catch the onSubmit event and then change the value to the new, |-delimited single value.  User never sees it, but it will be posted to the server like you want.

Demo here: http://jsfiddle.net/sanford/1cvgxwkb/
Candyce_Coving1
Level 2

Re: How to change separation character in multi-selection form field

Sanford, Very cool and sophisticated! Thank you for sharing this!
SanfordWhiteman
Level 10 - Community Moderator

Re: How to change separation character in multi-selection form field

No prob. Might even use it myself! And will add to my Forms 2.0 Cookboook... whenever that comes out.