BuddyDev

Search

[Resolved] Fetch and condition for checkboxes data values

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #44075

    Hello Ravi,

    Thank you very much for your feedback.
    Your code works perfect and gives the results you mentioned. However what i need is:

    // If all three options are selected.
    TEXT WILL BE SEND

    // If option Music and option Food are selected.
    TEXT WILL BE SEND

    // If option Music and option Movie are selected.
    TEXT WILL BE SEND

    // If option Movie and option Food are selected.
    TEXT WILL BE SEND

    // If only option Movie is selected.
    TEXT WILL BE SEND

    // If only option Food is selected.
    TEXT WILL BE SEND

    // If only option Music is selected.
    TEXT WILL BE SEND

    The text is irrelevant to the conditions programmatically and dont need to fetch the array $data inside the $message . Just need the conditions for every option of the user.

    Regards Lefteris

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #44095

    Hello Lefteris,

    Thank you for the detailed acknowledgement. Please use the following code with as many possible conditions:

    
    
    $data  = (array) xprofile_get_field_data( 12, 23 );
    
    $is_selected_music  = in_array( 'Music', $data );
    $is_selected_food   = in_array( 'Food', $data );
    $is_selected_movies = in_array( 'Movies', $data );
    
    $message = '';
    
    // Example for all selected.
    if ( $is_selected_food && $is_selected_movies && $is_selected_music ) {
    	$message = __( 'All are selected' );
    }
    
    echo esc_html( $message );
    
    

    Please let me know if it helps or not.

    Regards
    Ravi

    • This reply was modified 2 years, 7 months ago by Ravi.
  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #44097

    Hello Ravi,

    Thank you very much for your feedback.Your code is giving the appropriate results. However the problem with this logic is that when user is checking $is_selected_food && $is_selected_movies the output is FOOD, MOVIE, FOOD & MOVIES. Actually it outputs all the 3 true cases :

    $is_selected_movies MOVIE
    $is_selected_food FOOD
    $is_selected_food && $is_selected_movies FOOD & MOVIES

    I have used only if statements inside my wp_mail.
    if ( empty( $data ) ) { // some html}
    if ( $is_selected_movies ) {// some other html}`
    if ( $is_selected_food ) { // some other html} and so on…

    If i set elseif, then i dont get correct results.

    If $is_selected_food && $is_selected_movies should be only this true.

    Regards Lefteris

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #44103

    Hello Lefteris,

    Try this

    
    
    $data  = (array) xprofile_get_field_data( 12, 23 );
    
    $is_selected_music  = in_array( 'Music', $data );
    $is_selected_food   = in_array( 'Food', $data );
    $is_selected_movies = in_array( 'Movies', $data );
    
    $message = '';
    
    // Example for all selected.
    if ( $is_selected_food && $is_selected_movies && $is_selected_music ) {
    	$message = __( 'All are selected' );
    } elseif ( $is_selected_music && $is_selected_movies ) {
    	$message = __( 'Music and Movies are selected' );
    } elseif ( $is_selected_food && $is_selected_movies ) {
    	$message = __( 'Food and Movies are selected' );
    } elseif ( $is_selected_food && $is_selected_music ) {
    	$message = __( 'Food and Music are selected' );
    } elseif ( $is_selected_movies ) {
    	$message = __( 'Movie is selected' );
    } elseif ( $is_selected_music ) {
    	$message = __( 'Music is selected' );
    } elseif ( $is_selected_food ) {
    	$message = __( 'Food is selected' );
    } else {
    	$message = __( 'No option is selected' );
    }
    
    echo esc_html( $message );
    
    

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 71
    Lefteris on #44105

    Hello Ravi,

    Thank you very much for your patience and support. You are truly remarkable. Now it works correct.

    Regards Lefteris

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #44111

    Hello Lefteris,

    Thank you for the acknowledgement. I am glad that I could help.

    Regards
    Ravi

The topic ‘ [Resolved] Fetch and condition for checkboxes data values’ is closed to new replies.

This topic is: resolved