The code necessary depends on the type of solenoid used and the method of wiring.
The code you posted is correct for a double solenoid (two red and two black wires) if the two red wires are wired to the spike and the grounds connect to ground elsewhere.
A single solenoid has one red and one black wire going to the spike and is controlled by (as in Roger's example):
Code:
if(p1_sw_trig)
{
relay1_fwd = 1;
relay1_rev = 0;
}
else
{
relay1_fwd = 0;
relay1_rev = 0;
}