Essentially, you just need to validate your state field if and only if the address field is not empty. This can be achieved with the following code:
if ( isset( $_POST[ 'address' ] ) && ! empty( $_POST[ 'address' ] ) ) {
// An address has been provided, so validate the state.
if ( ! isset( $_POST[ 'state' ] ) || ! in_array( $_POST[ 'state' ], $valid_states ) ) {
// There was an error: the address is set but the state is not.
}
}
Keep in mind that $valid_states
in the above code represents an array of all the state values from the select list that should be accepted by the form. For example:
$valid_states = array(
'KY', 'IL', 'FL', 'WY', /* ... */
);
You could also add some JavaScript to your form to completely hide the state field if the address field is not populated. Since state will only be validated if address is populated, it's existence on the form will not matter.