This isn't a trivial matter that reduces to a standard form, but it's not wildly complicated either. Basically, you need to think about what rights you want protected and what you're willing to give up in exchange for that, and you also need to look at the matter from the neighbor's perspective (addressing the same questions). His fence is (presumably) on his property, so you would be building onto his property, and that raises the specter of adverse possession (where you can later claim ownership of some of his property). This can be dealt with by him giving you revocable permission to extend your fence to his land. Both sides would need to decide (and say) what happens if one side wants to tear the fence down, or if it is damaged (either part of the fence). You have to decide if you want an actual contract (where you gain a right) which means that each side has to give something value in exchange, or do you simply want permission (which I suspect is not what you want, since you want something that would "hold up in court", meaning that the neighbor has to do something). The contract should also clearly state exactly you mean by "attach your fence", and of course if what he wants is that you reimburse him for some portion of his construction costs, that amount needs to be stated clearly.
In other words, you have to hire an attorney, or write the agreement yourself and hope that it isn't screwed up (by contradicting the law including local ordinances, or being so badly written that nobody can figure out what you're agreeing to, or not contemplating a circumstance that may arise that an attorney would cover).