Form helper: refactor form_open() and _attributes_to_string()

Nicer code and improve solution for #2560