You can indeed use the forms onsubmit handler for this, and in my opinion you really should. It's what it's there for. However, you must make the event handler return the value of the function call
<form onsubmit="return f();">
Which of course also means f must return a proper value (false to prevent form submit, non-false to allow it).
In the same way, you could use the onclick handler for the submit button to stop event propagation.
<input type="submit" onclick="return f();" />
In my opinion it doesn't really matter wether you use submit buttons' onclick or forms' onsubmit handler, but stay consistent.
Also, iirc, it is necessary (or was in some browser(s)) to include the trailing ; for this to work. All I do know for sure is that it's not presently required by FF. But if things don't work as they should, check that it's: onsubmit="return f();" rather than onsubmit="return f()"