Hi
Based on a selection field, you get different questions after that depending on the selection chosen. This works with this plugin, great! But when these questions are mandatory this doesn’t work, because you have to fill in all the mandatory fields, even the ones that are not shown. Is there a way to override this behaviour.
I don’t get any javascript errors on this page.
Anyone have an idea whats wrong?Hi Dennis,
Thank you for posting.this is the way BuddyPress deals with the required field. It is possible to overcome that but in that case what is the benefit of having a required field?
We have left it as it is since the users will be able to bypass reqired fields if we modified the behaviour.
Regards
BrajesHi 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.
DennisHi Dennis,
I am sorry for the inconvenience.If I was in this situation, I will mark the checkbox non required in admin and do a custom validation on ‘bp_signup_validate’ action to make sure that one of the checkbox is checked.
I do understand that it is not a very suitable option for the site admins. I am willing to assit you if you can tell me the field ids and their dependency on the checkbox.
Thank you
BrajeshOk,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!Thank you Denis,
I and my team will be a bit off tomorrow. Please allow me to post a solution on Monday.Thank you
BrajeshHi Dennis,
Here is the examplefunction buddydev_validate_field_dennis() { $field_1 = 12;//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 == 'a' ) { //check if question 2( assume field id 13) is present if ( empty( $_POST['field_13'] ) ) { $bp->signup->errors['field_13'] = 'This is a required field, you should not askip it'; } } elseif ( $value == 'b' ) { //in this case, field_14, field_15, field_16 is required $required_fields = array( 14, 15, 16 ); 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' );
You will need to update the field ids and the value of the first field( ‘a’, ‘b’ with actual values)
I hope you can take it from there.
Regards
Brajesh
The topic ‘ [Resolved] Conditional Profile Fields’ is closed to new replies.