I have a website containing a lot of different contact forms. I want to keep an array of their ID's (and other related settings) so I can loop through them and add submit handlers to each one.
The problem is that only the last form in the array seems to get a handler attached to it.
List of forms:
forms = [
{id: '#contact-form-1', ...},
{id: '#contact-form-2', ...}
]
How I'm trying to add submit handlers:
for (i in forms) {
$(document).on('submit', forms[i].id, function(){
// Validation, send email etc.
}
}
Is $(document).on() the right way to approach this? I have tried $(forms[i].id).submit(); but I get the same outcome; only the last form in the list gets bound to.