A flag is a variable that you declare and change according to the state of what you need to record.
You can declare a Boolean buttonPressed = FALSE
In the main loop
If button is pressed and buttonPressed is FALSE. If not already pressed
buttonPressed = TRUE. Will stop future activation
Turn on solenoid for time required
If button is released
buttonPressed = FALSE. Will allow to operate next time
Weedpharma