After a long time I discovered the problem by myself. This invalid form error occurs because normally, on local machines, the protocol is http instead of https. So just change the Magento settings to not use secure URLs in both the store and the admin.
You can find these settings in:
Change the following values to no:
1 - Use Secure URLs in the Store.
2 - Use Secure URLs in the Administration Section.