This code might be slightly slower because it performs one query per field in the form, but I didn't notice any differences on my development machine, and the code is now much easier to understand.