I'm not sure that I understand everything that you requested, but if you want to get "foo" and "bar" when the user submits the form, you will have to add them to the form element, for example, hidden or text fields (depending on if the user can change them or not).
The server will not receive the entire DOM when submitting the form.
In addition, you will need to find a way to indicate which flag belongs to foo and bar.
source
share