Refactored form field creation logic