First Part of my post :
Ok, after several hours of testing and debugging, I found my problem. I'll try to explain this with my bad English.
The first thing is that I have the general parameter of the conditional plugin "Reset" => Enabled.
The second thing is a problem in the code when you reset the field value even for a delimiter field.
file : tab.cbconditional.php line 86
Code:
86 if ( $condition->hide ) {
87 foreach ( $fields as $k => $v ) {
88 if ( in_array( (int) $v->fieldid, $condition->hide ) ) {
89 if ( $plugin->params->get( 'cond_reset', 0 ) ) {
90 $field_name = $v->name;
91 $user->$field_name = '';
92 }
93 unset( $fields[$k] );
94 }
95 }
96 }
The field value is initialized at line 91, but, if the field name does not exist in the variable $user (as a field delimiter) the field name is added. This is why we find the delimiter field in the request.
I modified the source code as follows (line 89):
Code:
86 if ( $condition->hide ) {
87 foreach ( $fields as $k => $v ) {
88 if ( in_array( (int) $v->fieldid, $condition->hide ) ) {
89 if ( $plugin->params->get( 'cond_reset', 0 ) && $v->type != 'delimiter' ) {
90 $field_name = $v->name;
91 $user->$field_name = '';
92 }
93 unset( $fields[$k] );
94 }
95 }
96 }
After that, in my case, everything seems OK.
But after several tests, I came to the conclusion that this reset option was not really usable in some complex cases where you want to reset the value for some fields and not for other fields. A possible improvement would be to have this property in each field and not in the plugin configuration.
Finally, I disabled this plugin option, and I used the Auto Actions plugin to reset value.
Second part of my post :
After a number of tests I found another issue in the CB plugin conditional. It is a little bit more complicated to explain.
I have a check box that shows or hides many other fields that are required if they are shown. In the register mode, there is no problem. But in the edit mode, I have a problem when I uncheck the box, in fact, at the server side when you controlled conditions you ignore the fields of type check box that sending no value when they are not checked. Therefore, you take the old value of the check box which makes the other fields required, which opens an error window indicating that these fields are required.
file : cbconditional.class.php line 560 and 767
Code:
if ( $_POST ) {
$post_user = new moscomprofilerUser( $_CB_database );
$post_user->bindThisUserFromDbArray( $user );
$post_user->bindThisUserFromDbArray( $_POST );
...
You first retrieve the old values ​​in the database and then you update with new data in the POST. But a unchecked check box is not in the POST. Therefore the conditional rule considers that the check box is checked.
I made a change for this to work well with the check box but I think that other types of fields are also concerned as multiple check box for example.
Code:
if ( $_POST ) {
$post_user = new moscomprofilerUser( $_CB_database );
$post_user->bindThisUserFromDbArray( $user );
$post_user->bindThisUserFromDbArray( $_POST );
foreach ( $fields as $field_cb ) {
if ( $field_cb->type == 'checkbox' )
{
if ( ! isset($_POST[$field_cb->name]) ) {
$post_user->set($field_cb->name, '0');
}
}
}
...
Well, I hope that all these remarks will be helpful in improving this plugin.
Best regards
Bruno