It shall be unlawful for any magistrate to appear as attorney at law in any of the courts of this State in any action which may have been before him in his official capacity as such magistrate. Any magistrate who violates the provisions of this section shall forfeit his office.