lundi 27 février 2017

PHP - MySql : How to store and retrieve checkbox value with other option

I using checkbox to get and store interest of user.

enter image description here

Store these data in database mysql with comma separated

enter image description here

My php code for retrive these data and display in html page

<?php

....

// Get data
$result = profile($uname);
$result['interest'] = explode(',', $result['interest']);

?>

....

<div class="col-sm-6">
    <div class="form-check checkbox-style">
        <label class="label-weight">Interests</label><br>
        <label class="form-check-label label-weight">
            <input type="checkbox" class="form-check-input" name="interest[]" onclick="return interest_validate(this);" id="selectall"><span class="check-label-pad"> Select all</span></label></label><label for="" class="opacity-set label-set" id="select-label"></label><br>
        <label class="form-check-label label-weight">
            <input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option1" <?php echo in_array('option1',$result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 1</span></label><br>
        <label class="form-check-label label-weight">
            <input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option2" <?php echo in_array('option2', $result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 2</span></label><br>
        <label class="form-check-label label-weight">
            <input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option3" <?php echo in_array('option3', $result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 3</span></label><br>
        <label class="form-check-label label-weight">
            <input type="checkbox" class="form-check-input" name="interest[]" id="other_checkbox" onclick=" return other_validate(this);" value="other"><span class="check-label-pad"  >Other</span> &nbsp;&nbsp;</label><input type="text " class="text-style-other opacity-set" id="other-text" onblur="return other_text_validate();" />
        <label for="" class="opacity-set label-set" id="other-text-label"></label>
    </div>
</div>

Issue : in edit mode, I am using "in_array()" for to give as default checked to checkbox as per database value. But how to check "Other" (check attached image) option and display value ? which condition i need to add here?




Aucun commentaire:

Enregistrer un commentaire