Forms 2.0 API — AddHiddenFields() and Checkboxes | Community
Skip to main content
New Participant
July 1, 2021
Question

Forms 2.0 API — AddHiddenFields() and Checkboxes

  • July 1, 2021
  • 1 reply
  • 2272 views

I'm working on our implementation of background form submission as described in this Marketo blog post, and suggested to us by their support team.

In doing so, we've run into a challenge (which was noted as "not so easy" in this previous forum answer).  We need to submit a checkbox group through a background form submission.

I've tried adding multiple checked values one at a time using `addHiddenFields()`...

 

myMktoForm.addHiddenFields( 'My_Field_Name', 'Checked Value 1' ); myMktoForm.addHiddenFields( 'My_Field_Name', 'Checked Value 2' ); myMktoForm.addHiddenFields( 'My_Field_Name', 'Checked Value 3' );

 

But when I call `getValues()` I only see the last one...

 

{ My_Field_Name: 'Checked Value 3' }

 

I've also tried adding them as an array...

 

myMktoForm.addHiddenFields( 'My_Field_Name', [ 'Checked Value 1', 'Checked Value 2', 'Checked Value 3' );

 

In that case the values in the array get merged into a comma-separated string...

 

{ My_Field_Name: 'Checked Value 1,Checked Value 2,Checked Value 3' }

 

So next, I tested a checkbox group on a Marketo landing page to see how the values were handled. If I add a checkbox group on a Marketo landing page, check some values, then call `getValues()`, the values appear to be kept as an array, not merged into a string...

 

{ My_Field_Name: [ 'Checked Value 1', 'Checked Value 2', 'Checked Value 3' ] }

 

So I'm a bit stuck at how to reproduce the expected behavior before submitting the background form... is there a clever way to add a hidden field containing an array of values using the Forms2 API?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
July 1, 2021

If a field isn’t on the form, then it isn’t actually a Checkboxes group — <input type="hidden"> is equivalent to <input type="text" hidden>.

 

let serializedMultiString = ['Checked Value 1','Checked Value 2','Checked Value 3'].join("; "); myMktoForm.addHiddenFields({ My_Field_Name : serializedMultiString });
jtremblayAuthor
New Participant
July 1, 2021

Thanks for the tip @sanfordwhiteman, I'll try that approach and report back.