I think you're tricking your mind into not being able to wrap around this because you're outputting the URL with the xxxxx in it. Don't display any output links until you've formatted it...
(You could look into using AJAX so you get a real time update of the boxes, but I won't get into that since you are a "newbie".
So, on your form, post back to your page. (Using the GET method should be fine).
Then on your page, you'd have something like:
$affiliate_url = "http://".$_GET['CBID'].".malacka2.hop.clickbank.net"
(That will create the link. From there, you can output it as a value in your form fields.)
Repost back if you need further guidance.
Please note, this is not tested and has no validation, or anything that will prevent SQL injection or anything like that. This is provided to give you some guidance on how to accomplish your goals.