Skip to Content Skip to Menu

🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

sql error on insertion in comprofile table

  • blussan
  • blussan
  • OFFLINE
  • Posts: 4
  • Thanks: 0
  • Karma: 0
12 years 4 months ago - 12 years 4 months ago #208077 by blussan
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
Last edit: 12 years 4 months ago by blussan. Reason: Code style

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
12 years 4 months ago #208175 by krileon
Thanks for the suggestions. Will review your suggestions and release as necessary. Some of your issues have already been fixed in latest (reset parameter not working properly; it's only supposed to take affect on POST). As for the delimiter fields showing in user object this simply needs a check added to ensure the field exists in the user object. The checkbox issue can be fixed by checking if the field exists in $_POST and if it doesn't then assume null (confirmed fix). Will release 1.8.6 later today addressing your issues.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum