How do I limit the movement of an object to two directions?
If i understand correctly, what you want to do in the picture with the U-shaped path can be achieved with a "Clamp to" constraint. (If you are familiar with drivers, then first see the EDIT below!!!) For this you clamp your Object that has to follow a curve-Object. The follower Object should then only be translatable along that set Path. Of course you could then have some other constraint move that path around if you want ;)

The result should look something like this:

And here an example for using additional constraints on the curve, where the curve copies the z-location of the blue cube: 

To do make the red cube go along the full path when the blue cube is moved you can use drivers. By the clamp to constraint the red object moves along the entire path only by manual transform alon the x-axis. So you could add a driver (rightclick-> add driver) to the the x-Location of the red cube and make the "input variable" the z-location of the blue cube. Then the result looks like this:

EDIT:  If you want to move that curve around in all directions, then the "follow path" constraint is much more stable. Just make a driver on the Offset, make the input variable whatever you want and you're done!

Happy Blending!