function buddydev_validate_field_dennis() {
$field_1 = field_65;//the first field which has two options
//since field one is required, we don’t validate if it is not present, Bp will take care of it
if ( ! isset( $_POST[ $field_1 ] ) ) {
return;
}$value = $_POST[ $field_1 ];////make sure to escape it , I don’t know expected type, so have left it.
//if we are here, one of the option has been selected, so
$bp = buddypress();
if ( $value == ‘Beneficiary’ ) {
//check if question 2( assume field id 13) is present
if ( empty( $_POST[‘field_180’] ) ) {
$bp->signup->errors[‘field_180’] = ‘Required field’;
}} elseif ( $value == ‘Candidate Country representative’ ) {
//in this case, field_14, field_15, field_16 is required
$required_fields = array( ‘field_141’, ‘field_143’, ‘field_42’ );
foreach ( $required_fields as $field_id ) {
if ( empty( $_POST[ ‘field_’ . $field_id ] ) ) {
$bp->signup->errors[ ‘field_’ . $field_id ] = ‘Required field.’;
}}
} else {
//not of the allowed value
$bp->signup->errors[ $field_1 ] = ‘Please make sure to use a valid value.’;
}
}add_action(‘bp_signup_validate’, ‘buddydev_validate_field_dennis’ );
Choosing no option or the first option works, but choosing the second option ( Candidate Country representatives) doesn’t work. It doesn’t submit when everyting is filled in and doesn’t give me errors when something required isn’t filled in.
Any ideas?Thank you Dennis. That’s good to know 🙂
Marking it as resolved.
The topic ‘ [Resolved] Conditional Profile Fields’ is closed to new replies.