How to add checkbox in Profile Page
-
Hi,
I liked to customize my profile page by adding new fields to get more info from the user like “Gender” or “Speaking Languages”. I managed to get the text input and radio button input to work, the problem I having now is on the checkbox type of input. Here is my code:function my_user_field( $user ) { $language = get_the_author_meta( 'language', $user->ID); ?> <h3><?php _e('More About You'); ?></h3> <table class="form-table"> <tr> <th> <label for="language"><?php _e('Language'); ?> </label></th> <td><input type="checkbox" name="language" <?php if ($english == 'yes' ) { ?>checked="checked"<?php }?> value="yes" /> English<br /> <input type="checkbox" name="language" <?php if ($mandarin == 'yes' ) { ?>checked="checked"<?php }?> value="yes" /> Mandarin<br /> </td> </tr> </table> <?php } function my_save_custom_user_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return FALSE; update_usermeta( $user_id, 'language', $_POST['language'] ); } add_action( 'show_user_profile', 'my_user_field' ); add_action( 'edit_user_profile', 'my_user_field' ); add_action( 'personal_options_update', 'my_save_custom_user_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_custom_user_profile_fields' );
The checkbox options are not mutually exclusive, they are multi select enable.
I wondering using array for language[], but I can’t make it right. Help please. Thanks
- The topic ‘How to add checkbox in Profile Page’ is closed to new replies.