Replies
- Lefteris on March 24, 2022 at 7:50 pm in reply to: [Resolved] Fetch and condition for checkboxes data values #44105
Hello Ravi,
Thank you very much for your patience and support. You are truly remarkable. Now it works correct.
Regards Lefteris
- Lefteris on March 24, 2022 at 4:18 pm in reply to: [Resolved] Fetch and condition for checkboxes data values #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 isFOOD, 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 & MOVIESI 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
- Lefteris on March 23, 2022 at 11:00 am in reply to: [Resolved] Fetch and condition for checkboxes data values #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 SENDThe 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
- Lefteris on March 22, 2022 at 10:35 pm in reply to: [Resolved] Fetch and condition for checkboxes data values #44042
Hello Ravi,
Thank you so much for your help ๐
I am sorry if i confused you. The
$message
information is not related with the$data
. Its just an introduction message text, and i don’t really need data from the$data
. The text ‘Food is selected’ was just an example. I just need to pass theif statements
for each users choice so that i can send with wp_mail the appropriate text accordingly.Regards Lefteris
- Lefteris on March 22, 2022 at 1:12 pm in reply to: [Resolved] Fetch and condition for checkboxes data values #44031
Hello Ravi,
Let me explain i bit better what i actually need to do ๐ On BP registration page i have a checkbox that users can check if they wish (optional field and not required).
Along with his checkbox preference i am sending a welcome email to the user.
Something like
function send_welcome_email_to_new_user($user_id) { $data = xprofile_get_field_data( 12, $user_id ); $message = sprintf( 'Hello' ) . "<br>"; if ( statements ) ) { $message .= sprintf( 'Music is selected' ) ."<br><br>"; } elseif ( statements ) ) { $message .= sprintf( 'Food is selected' ) ."<br><br>"; }elseif ( statements ) ) { $message .= sprintf( 'Food and music are selected' ) ."<br><br>"; } $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($to, $subject, $message,$headers); } add_action( 'bp_core_activated_user', 'send_welcome_email_to_new_user');
So actually i need the structure that we have been speaking about before ๐
Regards Lefteris
- Lefteris on March 22, 2022 at 9:56 am in reply to: [Resolved] Fetch and condition for checkboxes data values #44016
Hello Ravi, thank you for your help ๐ This is what happens with
elseif
statements:$data = xprofile_get_field_data( 12, 23, โcommaโ); if ( ! $data ) { echo "No item is selected";} elseif ( in_array( โMusicโ, $data ) ) { echo "Music is selected";} -> outputs: Music is selected elseif ( ! array_diff( array( 'Music', 'Movies' ), $data ) ) { echo "Music and Movies are selected";} -> outputs: Music is selected (should output: Music and Movies are selected ) elseif ( ! array_diff( array( 'Music', 'Movies', 'Food' ), $data ) ) { echo "All are selected";}
-> outputs: Movies is selected (should output: All are selected )
I will need to have only one output result according to users checks.
With the previous code with only
if
statements , i was getting as an output for example:if ( ! array_diff( array( 'Music', 'Movies', 'Food' ), $data ) ) { echo "All are selected";}
-> outputs: Music Movies Food Music is selected Food is selected Movies is selected Music and Movies are selected Music and Food are selected…. (because it was outputting all the
if's
. Should just output: All are selected )I hope this helps
Regards Lefteris
- Lefteris on March 22, 2022 at 9:06 am in reply to: [Resolved] Fetch and condition for checkboxes data values #44012
Hello Ravi,
Now it works, but there is one problem. The output is giving me results for each if that is
true
.So i have tried to set
elseif
because i would like only one output according to users checks. Withelseif
i get correct results only for this type of statements.if ( in_array( โMusicโ, $data ) ) { // Music is selected.}
For
array_diff
statements i get wrong results.Regards Lefteris
- Lefteris on March 22, 2022 at 8:10 am in reply to: [Resolved] Fetch and condition for checkboxes data values #44007
Hello Ravi, I did something like this. I didn’t use
elseif
.`$data = xprofile_get_field_data( 12, 23, ‘comma’);
if ( ! $data ) { // No item is selected.}
if ( in_array( ‘Music’, $data ) ) { // Music is selected.}
if ( in_array( ‘Music’, ‘Movies’, $data ) ) { // Music and movie is selected.}
if ( in_array( ‘Music’, ‘Movies’, ‘Food’, $data ) ) { // All is selected.}`
Regards Lefteris
- Lefteris on March 22, 2022 at 7:38 am in reply to: [Resolved] Fetch and condition for checkboxes data values #44005
Hello Ravi,
Thank you for your help. I have tried this and it work fine. However when the user ticks 2 out of 3 checkboxes, or all checkboxes. it doesn’t work. Any ideas?
Regards Lefteris
- Lefteris on March 21, 2022 at 1:45 pm in reply to: [Resolved] Fetch and condition for checkboxes data values #43991
I am sorry for the confusion Ravi, yes it gives me a correct result
Music , Movies , Food
. But how i can create an if statement to see if music is ticked, or if music+food is ticked, or if none is ticked?