Currently, I have a microsite which is being used as a form to insert / update data in a data extension.
In data extension, email is NOT a primary key so I can have multiple records for same email because I have a column called "Group". So email@example.com can exist more than once in the data extension with GroupA, GroupB and GroupC as 3 different rows.
Here is the code / AMPScript
I open the contact / row details like this:
%%[ var @DEColumnEmail, @DEColumnFirstName, @DEColumnLastName, @DEColumnGroup set @row = row(@rows,@i) set @DEColumnEmail = field(@row,"Email") set @DEColumnFirstName = field(@row,"First Name") set @DEColumnLastName = field(@row,"Last Name") set @DEColumnGroup = field(@row,"Group") ]%% <input type="text" name="email" id="email" value="%%=v(@DEColumnEmail)=%%"><br/> <input type="text" name="fname" id="fname" value="%%=v(@DEColumnFirstName)=%%"><br/> <input type="text" name="lname" id="lname" value="%%=v(@DEColumnLastName)=%%"><br/> <input type="text" name="Group" id="Group" value="%%=v(@DEColumnGroup)=%%">
Then to update the record, I use another page where I pass on the values and run UpsertDE AMPScript like this
SET @Email_Address = RequestParameter("email") SET @First_Name = RequestParameter("fname") SET @Last_Name = RequestParameter("lname") SET @Group = RequestParameter("Group") IF IsEmailAddress(@Email_Address) THEN /* Add/update the record to the appropriate DE */ UpsertDE("DATA_EXTENSION_NAME",1,"Email",@Email_Address,"First Name",@First_Name,"Last Name",@Last_Name,"Group",@Group) ENDIF /* Redirect to the confirmation page */ Redirect(@RedirectURL) ELSE /* The text below will be displayed in case of error */ SET @ErrorMessage = "There was an error in your submission. Please return to the previous page and try again." ENDIF
The limitation of this approach is that, I am only able to update / add one row at a time. I would like to add the record and if there are more Groups then I want to insert / update record just once instead of 3 manual steps.
For group, I want to display checkbox list like this:
<input type="checkbox" name="Group" value="GroupA"> GroupA<br> <input type="checkbox" name="Group" value="GroupB"> GroupB<br> <input type="checkbox" name="Group" value="GroupC"> GroupB<br>
And based on the selected values, 1, 2 or 3 rows should be added / updated in the data extension.
Any advice on what should be my approach or how my code / AMPScript should look look?