• Resolved melchi2

    (@melchi2)


    Hello,

    On the profile page in the account form I created a “free tonight” field to indicate to members that the person may be available for an evening meeting. Then I wanted to set up a clickable button to say yes or no.
    The system works well but it blocks the modification of the profile, can you tell me where the error lies.

    1 Code

    function shortcode_libre_ce_soir(){
    	
    	// Récupération de la valeur de l'user
    	$user_id = um_user("ID");
    	um_fetch_user( $user_id );
    
    	// Récupération de la valeur du champ LCS
    	$libre_ce_soir = um_user( "libre_ce_soir" );
    
    	// En fonction de la valeur du champ LCS
    	if ( $libre_ce_soir[0] == "Non" || $libre_ce_soir == "Non" ) {
    		$checked = "";
    	} else {
    		$checked = "checked";
    	}
    	
    	if ( isset($_GET['form']) && $_GET['form'] == "lcs_submit" ) {
    		
    		if ( isset($_GET['lcs']) && $_GET['lcs'] = "oui" ) {
    			$checkbox_value = true;
    		} else {
    			$checkbox_value = false;
    		}
    		
    		if ( $checkbox_value ) {
    			$valeur = "Oui";
    			$checked = "checked";
    		} else {
    			$valeur = "Non";
    			$checked = "";
    		}
    		
    		// Modification et application de la valeur du champ LCS
    		$libre[] = array( 'libre_ce_soir' => $valeur );
    		UM()->user()->update_profile( $libre );
    		update_user_meta( $user_id, 'libre_ce_soir', $valeur );
    
    		// Suppression du cache de l'utilisateur
    		UM()->user()->remove_cache( $user_id );
    	}
    
    	
    	echo '<div class="um-lcs-button">';
    	echo '<span>Libre ce soir ?</span>';
    	echo '<form id="form_lcs" method="get">';
    	echo '<input class="tgl tgl-flip" id="lcs" name="lcs" value="oui" type="checkbox" '.$checked.' onchange="document.getElementById(\'lcs_submit\').click()" />';
        echo '<label class="tgl-btn" data-tg-off="Non" data-tg-on="Oui!" for="lcs"></label>';
    	echo '<input type="submit" id="lcs_submit" name="form" value="lcs_submit" />';
    	echo '</form>';
    	echo '</div>';
    }
    add_shortcode('libre_ce_soir', 'shortcode_libre_ce_soir');

    2 Code

    add_action( 'um_profile_navbar', 'my_profile_navbar', 10, 1 );
    
    function my_profile_navbar( $args ) {
    	echo do_shortcode( '[libre_ce_soir]' );
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @melchi2

    Since UM profile is already inside a form on edit mode, adding a form inside it creates some conflict. There are 2 ways to solve it:

    • Just add a button inside the profile and place the form outside the form, use the button to trigger the form.
    • Add form only in view mode.

    You can try to modify your codes to something link following:

    add_action( 'um_profile_navbar', 'my_profile_navbar', 10, 1 );
    function my_profile_navbar( $args ) {
        if( ! UM()->fields()->editing ){
    	echo do_shortcode( '[libre_ce_soir]' );
        }
    }

    Regards,

    Thread Starter melchi2

    (@melchi2)

    Thank you a thousand times it works it’s really great.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Block edit profile’ is closed to new replies.