1

We have a Data extension (DE) where our users will have used checkboxes to select one or more items relating to a specific field. While the form Posts the data correctly and saves the multiple selections to the data extension as expected, the challenge is reviewing the selection and correctly checking the correct boxes when it displays. So this:

    <input type="checkbox" name="Brand" value="Solution1" %%[ IF v(@Brand) == "Solution1," THEN ]%%checked%%[ ENDIF ]%%/>Solution1
<input type="checkbox" name="Brand" value="Solution2" %%[ IF v(@Brand) == "Solution2," THEN ]%%checked%%[ ENDIF ]%%/>Solution2
<input type="checkbox" name="Brand" value="Solution3" %%[ IF v(@Brand) == "Solution3," THEN ]%%checked%%[ ENDIF ]%%/>Solution3
<input type="checkbox" name="Brand" value="Solution4" %%[ IF v(@Brand) == "Solution4," THEN ]%%checked%%[ ENDIF ]%%/>Solution4

Will correctly save to the DE whichever "solutions" are selected, but when reading back in, it's not displaying correctly. A flaw of the logic might be that it needs to be asking for "contains" rather than == but I detect some issues with that perhaps confusing a smaller string within a larger one (ie. 12345 contains 345 but doesn't match) I've worked with PHP scripts that require []'s following each item to post an array but that is also different from getting the info.
When one checks two items (ie. 1 and 3) the system, by default, sets the field value to

"solution1,solution3"

thus the IF statement above will be incorrect even if "solution1" is one of the fields values.
UPDATE The multiple checkboxes set up the comma delimited string in the related DE field. Additional scripting is required to parse through this and it's been suggested that we implement the BuildRowsetFromString() (BRSFS) function to loop through that set. My first take was an attempt to see the returned value of BRSFS when it parses through the applicable DE field. Using v(@fieldRS) though is not returning a visible value to display on the page. I understand that the script will now need to loop and parse through the field as an array to confirm the checked setting for the any number of checkboxes. Any suggestions on usage or detailing are welcome.

1

The "v()" operation is only meant to be used in line, in this case, inside %%=v()=%%, and is not necessary inside %%[]%%. Your if statements should be modified to say IF @Brand == "Solution1,"

Etc.

  • Timothy, I changed the code to reflect the unnecessary v() function and see it's not required but don't see that it interfered with this process. Was wondering if you had any other ideas as to why this wouldn't display correctly. I combed through the code over and over and everything else works. Have you built anything that uses these elements (checkbox, multi-select, AMPscript and Data Extensions) and works? – Jonny Shaw May 15 '14 at 17:12
  • Have you looked at the generated HTML for any obvious errors? I have made a landing page with checkboxes when the checked property gets set by AMPscript, yes. Could you print out your Brand values and add them to this thread? – Timothy May 15 '14 at 17:31
  • One more thought... is your page forcing XHTML as your markup? Maybe something with xmlns="w3.org/1999/xhtml". XHTML requires checked="checked" as the way to set the checkbox. – Timothy May 15 '14 at 17:36
  • Currently I have the brands values set simply to 1 or 2 or 3 for simplification reasons. The landing page setting is html 5 set in ET. I'll try using checked=checked and see if that makes the difference. – Jonny Shaw May 15 '14 at 20:51
  • Tried checked="checked" and that didn't help either. Will try to create an isolated test to review and share in the morning. – Jonny Shaw May 15 '14 at 20:58
1

As Tim states, you need to remove the v() function inside the AMPscript block.

<input type="checkbox" name="Brand" value="Solution1" %%[ IF @Brand == "Solution1," THEN ]%%checked%%[ ENDIF ]%%/>Solution1
<input type="checkbox" name="Brand" value="Solution2" %%[ IF @Brand == "Solution2," THEN ]%%checked%%[ ENDIF ]%%/>Solution2
<input type="checkbox" name="Brand" value="Solution3" %%[ IF @Brand == "Solution3," THEN ]%%checked%%[ ENDIF ]%%/>Solution3
<input type="checkbox" name="Brand" value="Solution4" %%[ IF @Brand == "Solution4," THEN ]%%checked%%[ ENDIF ]%%/>Solution4

Edit Based on the info in comments, you will need to parse out the values from the data extension using BuildRowSetFromString() to do all of this server side.

You might also consider bringing in the entire string to the front end code and checking them after the DOM is loaded using Javascript.

  • Didn't seem to make any difference. From what I see, the "v()" appears unnecessary but didn't interfere with the function. When removed, it still writes to the DE yet doesn't "check" the checkboxes when it displays the record. I also tried with and without the commas which are used as delimiters within the "Brand" field. – Jonny Shaw May 15 '14 at 15:12
  • Based on the code I'm seeing, that's the only thing that would cause an issue. It must be somewhere else in your code then. Try providing more information so we can take a look. – Kelly J Andrews May 15 '14 at 15:19
  • My experiment now was to simplify it using simple numbers to determine and set the value. Then display the V(@Brand) and give that a thought. I realized that 1,3 does NOT == 1 or 3 so maybe that won't work. A workaround might be to create each scenario as an if then (if @brand = 1,3 then... and have one set to checked and three) but coding all possible combinations will get ridiculous. hmmmm.... – Jonny Shaw May 15 '14 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.