Downlink based on user input in form Widget

Downlink based on user input in form Widget

I want to set downlink to configure the end device.
  1. User will give the input in input widget from Dashboard.
  2. There will be a submit button which will save user input field data.
  3. When user Toggle the Downlink Button, It will compare the changed fields and send downlink with Action.
  4. Based on the valid fields value, it will add hex key to payload and then hex field value.
I tried with Example template to send downlink to TTN and it worked also.
Now how to do this to configure device ?