In addition to supporting the back, like sitting in front of a wall, you can also try to elevate the pelvis, eg. by sitting on a pillow. That allows the pelvis to tilt, while you are upright. You can also use a strap (but only to stabilize, not to pull yourself forward).
There is no use in struggling yourself through these poses, as it would put a lot of unnecessary stress on your lower back.
On bending the knees: try to keep them straight, but if your back is still compromised, ie. you are unable to keep it straight and lengthened, even with all the given adjustments, then you should bend the knees.
Protecting your back should be the first priority in this posture. Bending the knees makes the stretch only slightly less effective, but much safer, if that means you can keep your spine straight and lengthened, keep breathing, and stay calm.
If you need to bend the knees, then you might find it useful to add some lying straight leg raises to your routine. They might be more effective for you than sitting forward bends, until you can keep your legs straight in sitting as well.
Note: You might occasionally see very flexible people bending forward with the spine slightly bent and the legs straight, but that is okay (for them). Their hamstrings are already flexible. The forces on the spine will not be that big, that is, they are able to bend the spine forward slightly without compressing it.