I am struggling with my weight at the moment but every time I go on a diet, I suffer from constipation. What can I do?

Quite a bit. Fiber can help your intestines hold on to enough fluid to keep your stool soft. Fiber also helps people feel full, and, since it isn't absorbed, adds no calories. Many fresh fruits & veggies, and whole grains are high in fiber. Drinking plenty of water will also help - aim for 2 liters per day while you're dieting. Finally exercise helps stimulate the bowels to keep things moving on the inside.
Eat whole foods. Simple sugars and processed carbs should be avoided or limited. This includes any flour product. The fine grind makes absorption quick, and spikes your blood sugar which increases Insulin and promotes weight gain. Good fats such as olive oil and coconut oil are fine in sensible amounts. Eat a rainbow of organic vegetables and 3-4 oz protein with each meal 5 hours apart. Take extra magnesium.