Replies
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?Ok,that’s above my skill level unfortunately, hope you can help.
Lets say question 1 has two answers, A & B.
If you choose answer A, question 2 shows up (because conditional) and is mandatory.
If you choose answer B, question 3, 4 and 5 show up (because conditional and are all 3 mandatory.
I can replace the ID’s if you can hook me up with some code and where to put it.
Tnx!Hi Brajes,
I understand what your saying, and also the benefit of a required field. But it’s only required if the question before has a conditional rule applied. Then some questions become irrelevant and therefor not visible, but are still required for others.Can you explain me how to overcome this? It’s an I Accept thickbox with different text for both conditinial rules. Depending on what they choose on the conditional question they have to agree with one text or the other, both required in the form but not both required for the person filling out the form.
Hope you can help.
Dennis