Create an ajaxevent onchange and your field will be a string separated by the given separator like ;
To use it you need to explode the fields to get a working array to be used with a foreach.
No issue.
Then you copy this code to a button. Then the behavior is different:
The field is no string any more but an array. So you can apply a foreach immediately
We are talking about the same (custom added) form field here. Use it in an ajax event and it’s a string, use it in a buttonclick and it’s an array. That’s not consistent, you need to make a decision here. Or string, or array, but not depending on use.