Better to trim those values after the form submission.
Once you put them into form,
user may also makes mistake by hitting space, right?
Also, by trimming all form fields after submission, you will
be sure that your DB is clean... no whitespaces on it.
Well unless someone insert data directly onto it :)