Viewing 15 replies - 1 through 15 (of 32 total)
  • Hey, I’m thinking, and I could be wrong that the database key might be the problem, that slash looks… not good to me. Just edit that to be a – and see how that fairs. If that works I’ll improve the key algorithm, I’m surprised it put a slash in there to begin with.

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Hey, thanks heaps for replying!

    I have a couple of extra fields with /’s in the key and seem to be working great for those. Just made another screenshot: https://cl.ly/image/080I0v1L2X19

    Still no luck though. I’m using radio’s for the project I’m on and just using Yes or No for them but having checkboxes would be sooo good as my instrument list is getting massive ??

    OK, interesting, well then I’ll check out checkboxes, it’s probably something stupid, but I’ll figure it out.

    Found the bug, it’s on line 173 of rpr-login.php

    echo "\n", '<input type="checkbox" name="', $meta_key, '[]" id="', $meta_key, '-', $option, '" value="$option" ';

    should be

    echo "\n", '<input type="checkbox" name="', $meta_key, '[]" id="', $meta_key, '-', $option, '" value="', $option, '" ';

    This change will make into 3.9.1 and future versions but that alone will get you going.

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Awesome!

    If it’s possible to answer. If my field is Instruments and options (checkboxes) are bass guitar, trumpet etc and they check bass guitar. Will the following code:

    the_author_meta(‘rpr_instruments’);

    output:

    bass guitar

    Haven’t tried it yet but presume that’s how the checkbox works. Thanks again really appreciate you having a look at code, will donate when project is complete. This really is an great plugin.

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Bugger just tried it and still not saving?

    On the registration side right? Because I just found a bug on the profile side with checkboxes while I was checking out the rest of the code around this feature. Line 158 of register-plus-redux.php needs to be changed.

    $value = get_magic_quotes_gpc() ? stripslashes( $_POST[$meta_field['meta_key']] ) : $_POST[$meta_field['meta_key']];

    to

    $value = get_magic_quotes_gpc() ? stripslashes_deep( $_POST[$meta_field['meta_key']] ) : $_POST[$meta_field['meta_key']];

    Also, you are correct, the_author_meta(‘rpr_instruments’) would output ‘bass guitar’, or ‘trumpet,bass guitar’ or whatever, comma separated.

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Cool they are saving now, only last little thing is that you now can’t uncheck. When you uncheck and hit save the options remain checked. I’m testing via the WordPress backend via the user edit page. Haven’t tested the registration process so see if the checkboxes save. At the moment I’m just editing current users, hope this helps.

    Ah, now that’s an interesting bug. I have a solution for that, but it won’t be a one liner… Give me a few minutes.

    OK, the code block starting on line 157, through 160 of register-plus-redux.php needs to change from:

    if ( array_key_exists( $meta_field['meta_key'], $_POST ) ) {
    	$value = get_magic_quotes_gpc() ? stripslashes_deep( $_POST[$meta_field['meta_key']] ) : $_POST[$meta_field['meta_key']];
    	$this->rpr_update_user_meta( $user_id, $meta_field, $value );
    }

    to

    $value = array_key_exists( $meta_field['meta_key'], $_POST ) ?  $_POST[$meta_field['meta_key']] : '';
    $value = get_magic_quotes_gpc() ? stripslashes_deep( $value ) : $value;
    $this->rpr_update_user_meta( $user_id, $meta_field, $value );

    The problem is that if a field gets nulled out, it never gets posted back, the If statement I had in place wasn’t allowing nulls to be saved.

    I hope you are done finding all my flaws because I’m heading to bed for the evening! Please let me know if you find anything else interesting or undesirable!

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Thankyou sooo much mate, I’ll keep working but I reckon this should be all good ??

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    Yip that was the fix!

    Thread Starter planktonwebdesign

    (@planktonwebdesign)

    One thing I noticed was that the output of the checkbox items using;

    the_author_meta('rpr_instruments');

    Bass Guitar Lessons,Trumpet Lessons,Theory Lessons

    is spat out as the following in my template

    bass_guitar_lessons,trumpet_lessons,theory_lessons

    but in the labels of the form, spacing and capitalisation is respected

    If I put spaces they are replaced with _’s. Is it possible to output the checkboxes as they appear in the labels? I know I can do a str_replace() but wondered if this is avoidable?

    Also I was keen to do a WP_User_Query query to see if the user had checked an option but the value contains all the checked options as above. Do think it is possible to do something like this if the user has checked multiple options?

    $professional_crew = array(
    			'role' => 'professional',
    			'meta_key' => rpr_instruments,
    			'meta_value' => 'theory_lessons'
        		);
    
    WP_User_Query($professional_crew);

    Well, I could, and perhaps should, do something about the parsing to underscores. The query question is trickier. You need to check against the meta_value using some kind of wildcard. I’ll look into how that would work functionally.

Viewing 15 replies - 1 through 15 (of 32 total)
  • The topic ‘[Plugin: Register Plus Redux 3.9] Checkbox value not saving’ is closed to new replies.