Custom field in the form not saving values in to the Database in magento 2.1checkboxes values not saving more...

Can I write a book of my D&D game?

Difference between i++ and (i)++ in C

Is using an 'empty' metaphor considered bad style?

Pythonのiterable

Do authors have to be politically correct in article-writing?

How to deal with an incendiary email that was recalled

I will be going to Sweden on business purpose .Can I visit London from Sweden and how much UK visa will cost?

Can a Pact of the Blade warlock use the correct existing pact magic weapon so it functions as a "Returning" weapon?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

How to prevent cleaning lady from hunging my lock screen in ubuntu 16.04

Making him into a bully (how to show mild violence)

What is the difference between rolling more dice versus fewer dice?

Does a phylactery of a lich have to be a box?

How should I handle players who ignore the session zero agreement?

How to say "Brexit" in Latin?

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Can you tell from a blurry photo if focus was too close or too far?

What are career options for big-picture thinkers with no experience?

Early credit roll before the end of the film

Is boss over stepping boundary/micromanaging?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Graph with overlapping labels

How to know if today is second or fourth Saturday

Cookies - Should the toggles be on?



Custom field in the form not saving values in to the Database in magento 2.1


checkboxes values not saving more then oneattribute value is not saving in databasehow to save checkbox values in database in magentoCustom checkbox field to change the customer groupMagento 2.1: How to make the custom form field in the checkout page requirednon editable form field in magento 2.1magento 2 - category attribute with checkbox input throws exception on admin saveMagento 2: setdata() is not saving the values into the databaseCustom Customer attribute not being created in database magento 2.1Magento 2: Custom input field values not saved in product form













3















I have created a custom attribute for customer using below code.




setup/installData.php




$customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'samsung', [
'type' => 'varchar',
'label' => 'Samsung ',
'input' => 'boolean',
'source' => '',
'required' => false,
'visible' => true,
'position' => 166,
'system' => false,
'backend' => ''
]);


$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'samsung')
->addData(['used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]]);
$attribute->save();


I am using below front-end code but data is not stored in the database:



<div class="field apple">
<div class="control">
<input type="checkbox" name="acs" id="apple" value="Apple" class="checkbox">apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="acs" id="samsung" value="Samsung" class="checkbox">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="acs" id="sony" value="Sony" class="checkbox">Sony
</div>
</div>
<div class="field dell">
<div class="control">
<input type="checkbox" name="acs" id="dell" value="Dell" class="checkbox">Dell
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>

<script type="text/javascript">
function selectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=true;
}
}

function UnSelectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=false;
}
}
</script>









share|improve this question

























  • Where is the code for saving? Write that too.

    – Sohel Rana
    Feb 21 at 16:04
















3















I have created a custom attribute for customer using below code.




setup/installData.php




$customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'samsung', [
'type' => 'varchar',
'label' => 'Samsung ',
'input' => 'boolean',
'source' => '',
'required' => false,
'visible' => true,
'position' => 166,
'system' => false,
'backend' => ''
]);


$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'samsung')
->addData(['used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]]);
$attribute->save();


I am using below front-end code but data is not stored in the database:



<div class="field apple">
<div class="control">
<input type="checkbox" name="acs" id="apple" value="Apple" class="checkbox">apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="acs" id="samsung" value="Samsung" class="checkbox">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="acs" id="sony" value="Sony" class="checkbox">Sony
</div>
</div>
<div class="field dell">
<div class="control">
<input type="checkbox" name="acs" id="dell" value="Dell" class="checkbox">Dell
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>

<script type="text/javascript">
function selectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=true;
}
}

function UnSelectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=false;
}
}
</script>









share|improve this question

























  • Where is the code for saving? Write that too.

    – Sohel Rana
    Feb 21 at 16:04














3












3








3








I have created a custom attribute for customer using below code.




setup/installData.php




$customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'samsung', [
'type' => 'varchar',
'label' => 'Samsung ',
'input' => 'boolean',
'source' => '',
'required' => false,
'visible' => true,
'position' => 166,
'system' => false,
'backend' => ''
]);


$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'samsung')
->addData(['used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]]);
$attribute->save();


I am using below front-end code but data is not stored in the database:



<div class="field apple">
<div class="control">
<input type="checkbox" name="acs" id="apple" value="Apple" class="checkbox">apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="acs" id="samsung" value="Samsung" class="checkbox">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="acs" id="sony" value="Sony" class="checkbox">Sony
</div>
</div>
<div class="field dell">
<div class="control">
<input type="checkbox" name="acs" id="dell" value="Dell" class="checkbox">Dell
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>

<script type="text/javascript">
function selectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=true;
}
}

function UnSelectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=false;
}
}
</script>









share|improve this question
















I have created a custom attribute for customer using below code.




setup/installData.php




$customerSetup->addAttribute(MagentoCustomerModelCustomer::ENTITY, 'samsung', [
'type' => 'varchar',
'label' => 'Samsung ',
'input' => 'boolean',
'source' => '',
'required' => false,
'visible' => true,
'position' => 166,
'system' => false,
'backend' => ''
]);


$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'samsung')
->addData(['used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]]);
$attribute->save();


I am using below front-end code but data is not stored in the database:



<div class="field apple">
<div class="control">
<input type="checkbox" name="acs" id="apple" value="Apple" class="checkbox">apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="acs" id="samsung" value="Samsung" class="checkbox">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="acs" id="sony" value="Sony" class="checkbox">Sony
</div>
</div>
<div class="field dell">
<div class="control">
<input type="checkbox" name="acs" id="dell" value="Dell" class="checkbox">Dell
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>

<script type="text/javascript">
function selectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=true;
}
}

function UnSelectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=false;
}
}
</script>






magento-2.1 javascript checkbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 21 at 16:57









Pawan

1,7682615




1,7682615










asked Feb 21 at 15:56









kirankiran

7511




7511













  • Where is the code for saving? Write that too.

    – Sohel Rana
    Feb 21 at 16:04



















  • Where is the code for saving? Write that too.

    – Sohel Rana
    Feb 21 at 16:04

















Where is the code for saving? Write that too.

– Sohel Rana
Feb 21 at 16:04





Where is the code for saving? Write that too.

– Sohel Rana
Feb 21 at 16:04










1 Answer
1






active

oldest

votes


















1














please use below code:



    <div class="field apple">
<div class="control">
<input type="checkbox" name="apple" id="apple" value="1" class="mycustomclass">Apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="samsung" id="samsung" value="1" class="mycustomclass">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="sony" id="sony" value="1" class="mycustomclass">Sony
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>

<script>
jQuery(document).ready(function() {
jQuery("#btn_checkall").click(function() {
jQuery("input.mycustomclass").each(function() {
jQuery(this).prop("checked", true);
});
});
jQuery("#btn_uncheckall").click(function() {
jQuery("input.mycustomclass").each(function() {
jQuery(this).prop("checked", false);
});
});
});
</script>





share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262897%2fcustom-field-in-the-form-not-saving-values-in-to-the-database-in-magento-2-1%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    please use below code:



        <div class="field apple">
    <div class="control">
    <input type="checkbox" name="apple" id="apple" value="1" class="mycustomclass">Apple
    </div>
    </div>
    <div class="field samsung">
    <div class="control">
    <input type="checkbox" name="samsung" id="samsung" value="1" class="mycustomclass">Samsung
    </div>
    </div>
    <div class="field sony">
    <div class="control">
    <input type="checkbox" name="sony" id="sony" value="1" class="mycustomclass">Sony
    </div>
    </div>
    <input type="button" onclick='selectAll()' value="Select All"/>
    <input type="button" onclick='UnSelectAll()' value="Unselect All"/>

    <script>
    jQuery(document).ready(function() {
    jQuery("#btn_checkall").click(function() {
    jQuery("input.mycustomclass").each(function() {
    jQuery(this).prop("checked", true);
    });
    });
    jQuery("#btn_uncheckall").click(function() {
    jQuery("input.mycustomclass").each(function() {
    jQuery(this).prop("checked", false);
    });
    });
    });
    </script>





    share|improve this answer






























      1














      please use below code:



          <div class="field apple">
      <div class="control">
      <input type="checkbox" name="apple" id="apple" value="1" class="mycustomclass">Apple
      </div>
      </div>
      <div class="field samsung">
      <div class="control">
      <input type="checkbox" name="samsung" id="samsung" value="1" class="mycustomclass">Samsung
      </div>
      </div>
      <div class="field sony">
      <div class="control">
      <input type="checkbox" name="sony" id="sony" value="1" class="mycustomclass">Sony
      </div>
      </div>
      <input type="button" onclick='selectAll()' value="Select All"/>
      <input type="button" onclick='UnSelectAll()' value="Unselect All"/>

      <script>
      jQuery(document).ready(function() {
      jQuery("#btn_checkall").click(function() {
      jQuery("input.mycustomclass").each(function() {
      jQuery(this).prop("checked", true);
      });
      });
      jQuery("#btn_uncheckall").click(function() {
      jQuery("input.mycustomclass").each(function() {
      jQuery(this).prop("checked", false);
      });
      });
      });
      </script>





      share|improve this answer




























        1












        1








        1







        please use below code:



            <div class="field apple">
        <div class="control">
        <input type="checkbox" name="apple" id="apple" value="1" class="mycustomclass">Apple
        </div>
        </div>
        <div class="field samsung">
        <div class="control">
        <input type="checkbox" name="samsung" id="samsung" value="1" class="mycustomclass">Samsung
        </div>
        </div>
        <div class="field sony">
        <div class="control">
        <input type="checkbox" name="sony" id="sony" value="1" class="mycustomclass">Sony
        </div>
        </div>
        <input type="button" onclick='selectAll()' value="Select All"/>
        <input type="button" onclick='UnSelectAll()' value="Unselect All"/>

        <script>
        jQuery(document).ready(function() {
        jQuery("#btn_checkall").click(function() {
        jQuery("input.mycustomclass").each(function() {
        jQuery(this).prop("checked", true);
        });
        });
        jQuery("#btn_uncheckall").click(function() {
        jQuery("input.mycustomclass").each(function() {
        jQuery(this).prop("checked", false);
        });
        });
        });
        </script>





        share|improve this answer















        please use below code:



            <div class="field apple">
        <div class="control">
        <input type="checkbox" name="apple" id="apple" value="1" class="mycustomclass">Apple
        </div>
        </div>
        <div class="field samsung">
        <div class="control">
        <input type="checkbox" name="samsung" id="samsung" value="1" class="mycustomclass">Samsung
        </div>
        </div>
        <div class="field sony">
        <div class="control">
        <input type="checkbox" name="sony" id="sony" value="1" class="mycustomclass">Sony
        </div>
        </div>
        <input type="button" onclick='selectAll()' value="Select All"/>
        <input type="button" onclick='UnSelectAll()' value="Unselect All"/>

        <script>
        jQuery(document).ready(function() {
        jQuery("#btn_checkall").click(function() {
        jQuery("input.mycustomclass").each(function() {
        jQuery(this).prop("checked", true);
        });
        });
        jQuery("#btn_uncheckall").click(function() {
        jQuery("input.mycustomclass").each(function() {
        jQuery(this).prop("checked", false);
        });
        });
        });
        </script>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 12 mins ago









        ABHISHEK TRIPATHI

        1,7321726




        1,7321726










        answered Feb 22 at 21:41









        kirankiran

        7511




        7511






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f262897%2fcustom-field-in-the-form-not-saving-values-in-to-the-database-in-magento-2-1%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

            How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

            夢乃愛華...