The power of a golf swing is in the hips, but the direction and accuracy is in the legs. If you are not properly using your legs in your swing, you have no control over where the ball will go.
The exercise to help you develop good leg movement in the golf swing is relatively easy to explain, but it takes a while to learn how to do it properly. Your knees need to follow your hips during the swing, and it is critical to keep your feet in place at all times. Place a golf club on the ground, and then line your feet up with the club, keeping your feet shoulder-width apart. For a few moments just stand with your feet apart flexing your knees up and down. This helps to loosen your knees up, and it gets you thinking about where your legs are in your stance.
After a few minutes of stretching, take your other club in your hands and extend your arms fully. Keep your back straight, and flex at the knees to get the club head to the ground as though you were addressing the ball.
Now practice bringing your club back and making sure your knees follow your hips. Keep your feet flat on the ground. If your back foot starts to come up on your back swing, start over and keep working on it until you can keep your foot down. If you allow your foot to come up then it will slip on your follow-through and you will lose much of your power and accuracy. Keep working on this until you are able to move your knees and hips together in the back swing.
On your follow-through, your front leg will act as the anchor. It will turn with your hips, but not nearly as much as your back leg will. When you are done with your follow-through, the knee of your back leg should be pointing the direction your ball went and your back foot should be up on its toes with the heel pointing directly away from the flight of the ball.
Your front leg and front foot have remained anchored and have not turned into the follow-through as your back leg did. This is how the legs are supposed to work in a proper golf swing.