DRY up form submit code