3

I am having custom form instead of smart capture from on my cloud page. This form having multiple check boxes. Now i want to show this form pre-filled if existing user visited to this page.

Users land on this page via email link and i am getting user email via parameters in URL.

Now i am able to get the values for check boxes by matching email in that data extension using amp script but the problem is all check boxes values save to 1 field in data extension separated by (,) coma.

So i don't know how to fill the check boxes checked by matching check boxes value with these values that are in 1 field only.

My AMPScript Code

%%[

var @Email, @lookupValue, @value

SET @lookupValue = RequestParameter('email')

SET @value = Lookup("DataDE", "FieldA", "Email", @lookupValue)


]%%

Please share next step

enter image description here

1 Answer 1

5

You can achieve this by using the BuildRowsetFromString AMPscript function, for example:

 SET @rowSet = BuildRowsetFromString(@value, ",")

This will build a rowset with as many rows as many values you have in that cell. You can then use a comparison to match the values that should have checked checkboxes. Here's the whole thing:

%%[
SET @value = Lookup("DataDE", "FieldA", "Email", emailaddr)
SET @rowSet = BuildRowsetFromString(@value, ",")
FOR @i=1 TO rowcount(@rowSet) DO
      set @row = Row(@rowset,@i)
      set @field = Field(@row,1)

IF @field ==  "value a" THEN
SET @valuea = "checked"
ELSEIF @field ==  "value b" THEN
SET @valueb = "checked"
ELSEIF @field ==  "value c" THEN
SET @valuec = "checked"
ELSEIF @field ==  "value d" THEN
SET @valued = "checked"
ELSEIF @field ==  "value e" THEN
SET @valuee = "checked"
ELSEIF @field ==  "value f" THEN
SET @valuef = "checked"
ENDIF

NEXT @i
]%%

@valuea: %%=v(@valuea)=%%
<br>
@valueb: %%=v(@valueb)=%%
<br>
@valuec: %%=v(@valuec)=%%
<br>
@valued: %%=v(@valued)=%%
<br>
@valuee: %%=v(@valuee)=%%
<br>
@valuef: %%=v(@valuef)=%%

And then include the values in your form:

 <form>
  <input type="checkbox" name="valuea" value="value a" %%=v(@valuea)=%%> value a<br>
    <input type="checkbox" name="valueb" value="value b" %%=v(@valueb)=%%> value b<br>
    <input type="checkbox" name="valuec" value="value c" %%=v(@valuec)=%%> value c<br>
    <input type="checkbox" name="valued" value="value d" %%=v(@valued)=%%> value d<br>
    <input type="checkbox" name="valuee" value="value e" %%=v(@valuee)=%%> value e<br>
    <input type="checkbox" name="valuef" value="value f" %%=v(@valuef)=%%> value f<br>
  <input type="submit" value="Submit">
</form>
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .