mercredi 27 septembre 2017

Use checkbox to save and read multiple values in Wordpress

I am trying to create a checkbox that saves multiple values like those below, i am working on a costum field for wordpress users. The problem is that I can only save the last checked box if i check any box above that one, it won't work. I want to be able to save as many values as the user checks ,one,two or all. Then I want to be able to read them one by one. I have no idea how to change this. But the saving part on the user_meta is working correctly because it saves the last value.

    <p> <p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
        <label for="area_profissao"><?php _e( 'Área de Intervenção Profissional'); ?></label><br/>
        <input type="checkbox" class="checkbox" name="area_profissao" id="area_profissao1" value="CAPDA" <?php if (get_the_author_meta( 'area_profissao', $user->ID) == 'CAPDA' ) { ?>checked="checked"<?php }?> />Crianças e adolescentes com perturbações do desenvolvimento e aprendizagem <br />
        <input type="checkbox" class="checkbox" name="area_profissao" id="area_profissao2" value="CMPIP" <?php if (get_the_author_meta( 'area_profissao', $user->ID) == 'CMPIP' ) { ?>checked="checked"<?php }?> />Crianças em meio pré-escolar e/ou Intervenção Precoce<br />
        <input type="checkbox" class="checkbox" name="area_profissao" id="area_profissao3" value="CACP" <?php if (get_the_author_meta( 'area_profissao', $user->ID) == 'CACP' ) { ?>checked="checked"<?php }?> />Crianças e adolescentes em contexto pedopsiquiátrico<br />
        <input type="checkbox" class="checkbox" name="area_profissao" id="area_profissao4" value="MA" <?php if (get_the_author_meta( 'area_profissao', $user->ID) == 'MA' ) { ?>checked="checked"<?php }?> />Meio Aquático<br />
        <input type="checkbox" class="checkbox" name="area_profissao" id="area_profissao5" value="SMAI" <?php if (get_the_author_meta( 'area_profissao', $user->ID) == 'SMAI' ) { ?>checked="checked"<?php }?> />Saúde mental do adulto e do idoso<br />
    </p>




Aucun commentaire:

Enregistrer un commentaire