I'm currently building a preferences update form (not the main default Marketing Cloud preferences centre, but a specific form for a small audience segment)

I'm pre-populating the form from a personalised link in an email. I've been able to pre-populate the text fields with their existing preferences like so:

<input type="text" id="Firstname" name="Firstname" value="%%=v(@Firstname)=%%" required="" required>

But I am struggling a little with the checkboxes (boolean).

In raw HTML, adding 'checked' as below pre-ticks the checkbox. I've stored this value based on an if statement in a variable

If IndexOf(@StudyRegion,@Region1) > 0 Then
    Set @RegionNE = "checked"
    Set @RegionNE = ""

So if they checked that box first time round, the IndexOf section of the query finds it in the string (created as a result of multiple checkboxes) which looks like 'Northern Ireland,Wales,Greater London,East Midlands' etc. If it finds the appropriate region it sets the RegionNE variable to 'checked'. I have tried putting this variable in the checkbox lines like this:

<input type="checkbox" name="Study region" id="North East" value="North East" %%=v(@RegionNE)=%% />

But it's clearly wrong as it causes the page to get a 500 error. What would be the right way of making this checkbox be checked if the variable was found to be 'checked'?

  • 1
    Are the variables StudyRegion and Region1 defined in your code. If either of these variables are null, I would guess it would result in a 500 error. Mar 7 '17 at 21:08

@TCassa, your approach appears correct. I've taken this approach many time before. I suspect it is just something minor in your code like a syntax issue or undefined variable.

I've started using a new approach in this scenario by using the IIF() function. This approach allows me to place the AMPScript code inline with my HTML.

<input type="checkbox" name="Study region" id="North East" value="North East" %%=IIF(@StudyRegion=="North East"," checked ","")=%%/>

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.