The Peninsular War is usually described as Napoleonic France fighting Spain, Portugal and Britain. Some Spaniards, the afrancesados (“Frenchified”), supported the monarchy of Joseph Bonaparte, but most of this support seems administrative or intellectual in nature. Were there any military formations of Spaniards that fought for Joseph, under either the Spanish or the French flags?
Yes, there were some Spaniards that fought for Joseph Bonaparte, but the numbers are absolutely minuscule, and they were never really trusted by the French forces. A few years ago, Luis Sorando published a book on the matter titled "El ejército español de José Napoleón (1808-1813)" where he documents as best as he can the story of these 25,000 soldiers.
In 1812, the great guerrilla leader Juan Martín Díez alias El Empecinado captured two banners in Guadalajara and sent them to the Ministry of War. They had belonged to a regiment of the French army formed entirely by Spanish soldiers. The Cortes of Cádiz considered this conduct absolutely scandalous, and they cannot be any harsher in their condemnation of those soldiers: "There shall exist no testimonies that transmit to the posterity the abominable conduct of the denaturalised Spanish who have dared held weapons against their own motherland". The banners were laid on the ground of the Alameda in Cádiz, walked over by all of the troops in the city, and later burnt.
The Cortes did an extremely thorough job of erasing the "abomination" from Spanish history, and hence in the Spanish archives there is not a single record of the units ever having existed. However, Sorando pieced everything together from French, Italian, and English archives, and even some soldiers' memoirs and correspondence impounded by the anti-Bonapartist faction.
The total number of troops, as previously stated, was some 20,000 to 25,000 men, a total of 12 regiments formed mostly by conscripts, peasants, and poor and desperate people. The officers were an entirely different matter, as they were generally liberal afrancesados that actually believed that Joseph Bonaparte would be a good king. The man in charge of raising such an army was Gonzalo O'Farrill, a Spaniard born in Cuba with Irish ancestry, who was Joseph's Minister of War, and he did as much as he could. The raising of an army of naturals made all the sense in the world, as if Joseph wanted to be and remain a King of Spain, he could not depend on a foreign occupation army, as that would make him even more unpopular.
Those 12 regiments gradually disappeared, not by the men falling in combat, as they rarely ever saw any combat action due to the French military authorities absolute distrust of these Spaniards, whom they saw as potential defectors and traitors who "would melt like snow" at the first sign of combat. Eventually there would be only one regiment, as the forces would be constantly reorganised, with the regiments being merged as soon as their numbers dwindled.