The insert code on line 129-165 definitely has to be moved up on the page... that is the cause of the header error.
Your naming convention with a dynamically named form element is going to prevent the server behavior from working without some hand coding. I'd suggest a premium support ticket to work on this. I'm sure we can get it working in an hour session, but it is beyond the scope of what I can debug and get working remotely.