$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>user meta - how to save multiple checkbox in usermeta and get it?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

user meta - how to save multiple checkbox in usermeta and get it?

matteradmin11PV0评论

I want to create a new part as multiple checkbox in user profile page that user can check their services.

But the issue is i do not know how to display the checked options after saving as checked and how to display checked options in another page by get_user_meta!!!

my codes:

<input type="checkbox" name="service_name[]" value="Architecture" >Architecture<br>
<input type="checkbox" name="service_name[]" value="Builders and Developeres">Builders and Developeres<br>
<input type="checkbox" name="service_name[]" value="Material Supplier">Material Supplier<br>
<input type="checkbox" name="service_name[]" value="Contractor">Contractor<br>
<input type="checkbox" name="service_name[]" value="Interior Decorator">Interior Decorator<br>
<input type="checkbox" name="service_name[]" value="Property Finance">Property Finance<br>

the way i save them in user meta table:

if( isset($_POST['service_name']) ){
    //$data=serialize($_POST['service_name']);
    $data = $_POST['service_name'];
    update_user_meta($userid, 'service_name', $data);
}  

i need your help

I want to create a new part as multiple checkbox in user profile page that user can check their services.

But the issue is i do not know how to display the checked options after saving as checked and how to display checked options in another page by get_user_meta!!!

my codes:

<input type="checkbox" name="service_name[]" value="Architecture" >Architecture<br>
<input type="checkbox" name="service_name[]" value="Builders and Developeres">Builders and Developeres<br>
<input type="checkbox" name="service_name[]" value="Material Supplier">Material Supplier<br>
<input type="checkbox" name="service_name[]" value="Contractor">Contractor<br>
<input type="checkbox" name="service_name[]" value="Interior Decorator">Interior Decorator<br>
<input type="checkbox" name="service_name[]" value="Property Finance">Property Finance<br>

the way i save them in user meta table:

if( isset($_POST['service_name']) ){
    //$data=serialize($_POST['service_name']);
    $data = $_POST['service_name'];
    update_user_meta($userid, 'service_name', $data);
}  

i need your help

Share Improve this question asked Mar 12, 2019 at 12:41 Sh.DehnaviSh.Dehnavi 1093 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

First get the data

$data = get_user_meta( $user_id, 'service_name', true);

You find an array of all entries in $data. You can do it this way:

<input type="checkbox" name="service_name[]" value="Architecture" <?php echo in_array('Architecture', $data) ? 'checked' : ''); ?>>Architecture<br>

Untested, but should work.

Post a comment

comment list (0)

  1. No comments so far