Сode re usage in form

Сode re usage in form

I have a big block of code using in a form and I would like to reuse it in different places "On user input".
It looks like Function; however, I also need to use not only operators llike input.name = something, but hide/show fields.
How can I organize this?

for example: can I transfer Form as an object to Custom Function? or some other way to avoid the repetition the same piece of code?