0
votes

I implemented some checkboxes in the frontend of a wordpress site to get some information from a registered user. I always asked them for example: "Are you a Designer?" or "Are you a Actor?" and set a checkbox beneath so they can check it or let it unchecked.

The Checkbox Code looks like:

<input  type="checkbox" name="new_user_designer" id="new_user_designer"  value="true" <?php if (esc_attr( get_the_author_meta(  "new_user_designer", $userdata->ID )) == "true") echo "checked";  ?> />

I save the Checkbox input with:

if ($_POST['new_user_designer'] != $user_info->new_user_designer)
    update_user_meta($user_info->ID, 'new_user_designer', sanitize_text_field($_POST['new_user_designer']));

So far, everything works great! But here is my Problem and i need your help. I will echo the checkbox value in the Authorbox of the user. I tried this code:

<?php echo $user_info->new_user_designer; ?>

The above code works to show the correct Checkbox status for each user, BUT it returns the value "true". Now, how can i change the output "true" to "Designer" or any custom word...??? Again, so if a user checks the Checkbox it should show Designer in the Author Box instead of only "true"?

Second Question:

If there is a solution for my first Question, i need some help to show multiple checked inputs from 2 or more checkboxes in a row if some user checks more than one checkbox. For example the user is a Designer and Actor, he checks 2 checkboxes and now it should show in the user Info Box:

Designer, Actor

1
Um, you're setting value="true" yourself on the input element. Does your code still work if you change that to whatever you want?mabi
Hi mabi, i tried to change the value="true" to value="Designer" but then the checkbox don´t show up checked after saving the changes. But with this change the output shows me "Designer" instead of "true"..?NewUser

1 Answers

0
votes

I feel you should change code below

<input  type="checkbox" name="new_user_designer" id="new_user_designer"  value="true" <?php if (esc_attr( get_the_author_meta(  "new_user_designer", $userdata->ID )) == "true") echo "checked";  ?> />

To

<input  type="checkbox" name="new_user_designer" id="new_user_designer"  value="Designer" <?php if (esc_attr( get_the_author_meta(  "new_user_designer", $userdata->ID )) == "Designer"){ echo "checked";}  ?> />