I heard that Spain was neutral during the first one but I don't really know what happened in the second one. I think someone named France has something to do with it. I am not sure.
I can fill in the blank for World War I somewhat.
The conservative government in Spain, under Eduardo Dato, declared neutrality on the same day the war began and the country remained aggressively neutral throughout the conflict, though in practice (as is the case with the United States for most of the conflict) this meant continuing to do business with both sides nominally, but really only the "allies" as the British blockade of Central nations was extraordinarily effective.
The tensions that would eventually engulf the Spanish government in the 1930's were already at work in Spain though, and there were powerful factions in the country that favoured both sides. The Mauristas were a conservative faction in Spain (more of a youth movement) that favoured the replacement of the titular Bourbon monarch Alfonso with Antonio Maura, a prolific statesman who served as the Prime Minister of Spain at no less than five separate intervals. The Mauristas favored closer ties to the Allies based on their reading of the 1907 Pact of Cartagena between with the governments at Paris and London aimed at limiting the spread of German colonial interests in North Africa.
Maura in 1915:
Spain has the position in northern Africa and in the western Mediterranean which was granted to her by that agreement, she has a community of interests with England and France and the reciprocal promise of maintaining and working in favor of this community, and of this status quo[,] was given by the powers concerned (1)
Opposing the Mauristas were the Carlists, who formed the reactionary wing of the conservative faction in Spain. Their goals included replacing the Parliamentary head of state in Spain with a new wing of the Bourbon dynasty, and generally favored closer association with the Central Powers (who generally sought to protect the interests of European monarchy).
The Spanish did well for themselves during the war by trading with the Allies. The government effectively tripled its gold reserves, allowing it to pay down the debt that had been slowly strangling Spain's ability to project power for centuries. The Spanish merchant fleet lost in excess of 140,000 tons to German submarines, and the Spanish government joined most neutral governments in strongly condemning the German policy of unrestricted submarine warfare. You can read a (translated) facsimile of the note they sent to the Imperial government here:
http://www.firstworldwar.com/source/uboat_spain.htm
In addition, while the Spanish military did not participate in any engagements, like the Netherlands, they interned combatant troops that turned up in their sovereign territory. In 1915 they interned a group of German soldiers who made their way into Spanish Guinea in North Africa.
(1) Cunningham, Charles H. (1917). "Spain and the War". The American Political Science Review 11 (3): 421–47. doi:10.2307/1944246.