How to fill form fields according to predefined conditions