I'm trying to create a profile page where users can edit their preferences, including subscriptions to multiple mailing lists. We have a normal double-opt-in process for the user to subscribe to one of the mailing lists. In the profile, they should be able to select more mailing lists and save that preference.
Form:

There will be two cases to subscribe the user to one of the lists:
- The user has already subscribed to the list before, so there is a binding in the database that we can update (this part works fine)
- The user has never been subscribed to the list. We have to create a new binding in the database (that doesn't work. why?)
This is my Script:
Code: Select all
## Mailing List 187
#if ($requestParameters.LIST01ID)
#set( $list01 = $requestParameters.LIST01 )
$BindingEntry.setMailinglistID( 187 ) )
$BindingEntry.setCustomerID($customerID)
#if($list01)
## get the binding from DB and check if successful
#if($BindingEntry.getUserBindingFromDB(1) == true))
## if the user has activated list01
#if($list01 == 1)
## subscribe the user
$BindingEntry.setUserStatus(0)
$BindingEntry.updateBindingInDB(1)
#else
## unsubscribe the user
$BindingEntry.setUserStatus(0)
$BindingEntry.updateBindingInDB(1)
#end
## There is no binding in the database yet
#else
#if($list01 == 1)
# create a new binding
$BindingEntry.setMailinglistID( 187 ) )
$BindingEntry.setCustomerID($customerID)
$BindingEntry.setUserType("W")
$BindingEntry.setUserStatus(1)
$BindingEntry.setUserRemark("added in profile")
$BindingEntry.setExitMailingID(0)
$BindingEntry.setMediaType(0)
#set ($res = $BindingEntry.insertNewBindingInDB(1))
#end
#end
#end
#end