There certainly were men who expressly went to war to keep slaves, but there were men who fought for other reasons, albeit some of them misguided.
While the war was fought for slavery on the grand scheme, it's rash to simply state every Confederate soldier was fighting on that premise, or that premise alone.