mercredi 4 avril 2018

How to insert multiple checkboxes value 0 (default) and 1 (for checked checkboxes) into Wordpress database

I have plugin development requirement - On activation of plugin, the plugin should create one database table and by default 35 fields with '0' value should be added. I have created a table named checkbox with 3 column inside id(int), chk_col(varchar), created_at(timestamp) created multiple checkboxes with value 1 as below -

<form action="#" id="frmPost">
    <label class="checkbox-inline">
      <input type="checkbox" name="seat[]" id="seat0" value="1">A1
    </label>
<button type="submit" name="submit" id ="btn btn-default">Submit</button>
  </form>

and I have script.js file where i have written validation code as below which is working fine

!(function($){
$(document).ready(function(){
    $('#frmPost').on('change', 'input[type=checkbox]', function(){
        if ($(this).is(':checked'))
            alert('Seat ' + $(this).closest('label').text() + ' added.');
        else
            alert('Seat ' + $(this).closest('label').text() + ' removed.');
    });
    $('#frmPost').submit(function() {
        var $fields = $(this).find("input[name='seat[]']:checked");
        if (!$fields.length) {
            alert('You must book/select at least one seat!');
            return false; // The form will *not* submit
        }
    });
});
})(window.jQuery);

and also main wp function file is containing all necessary code Problem is - I really don't understand how to insert multiple checkboxes checked value of 1 into WP Db. I have tried to do so but not worked at all even serialization also not able to get processed. Help me to proceed further. Thank you.




Aucun commentaire:

Enregistrer un commentaire