How to add custom checkbox field to customer in magento?

How to add custom checkbox field to customer in magento?

July 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add custom checkbox field to customer in magento?

Solving Checkbox Field Issues in Magento Customer Form

As an experienced Magento developer, I often encounter situations where custom attributes need to be added to customer entities. In this post, we’ll delve into the process of adding a checkbox field to your Magento customer form and resolve some common issues that may arise during implementation.

Understanding the Issue: Custom Checkbox Field Not Saving

You’ve already attempted to add a custom checkbox field (marketattended1) under the customer entity. The code for this is as follows:

$setup->addAttribute('customer', 'marketattended1', array(
    'input' => 'checkbox',
    'type'  => 'int',
    'label' => 'San Francisco International Gift Fair',
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
));

// Add attribute to the appropriate group and set order
$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'marketattended1',
    '999'
);

// Save the attribute configuration
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();

However, you’re facing a critical issue: when trying to save or edit a customer record, the “Please wait” indicator never disappears. Instead, you encounter an error message stating “Call to a member function setAttribute() on a non-object.”

The Core Problem: Incompatible Attribute Types

The core issue lies in the attribute type and input specified for your checkbox field.

'input' => 'checkbox',
'type'  => 'int',

While you’re using the input value of ‘checkbox’, the type is still set to ‘int’. This discrepancy causes Magento’s EAV (Entity-Attribute-Value) model to fail when attempting to process and save the attribute data.

The Solution: Using Boolean Attribute Type

To resolve this issue, we need to ensure consistency between the input type and the EAV model’s requirements. For checkbox fields in Magento, the recommended approach is to use the boolean attribute type:

$setup->addAttribute('customer', 'marketattended1', array(
    'input'         => 'checkbox',
    'type'          => 'boolean',
    'label'         => 'San Francisco International Gift Fair',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
));

// Add attribute to the appropriate group and set order
$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'marketattended1',
    '999'
);

// Save the attribute configuration
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();

By changing the type to 'boolean', Magento will correctly interpret and process your checkbox field, allowing customers to be saved or edited without encountering any errors.

Display Custom Checkbox Field in Customer Form

After resolving the saving issue, you may wonder how to display this custom checkbox field in the customer registration form. You’ve already attempted to use HTML markup:

<input class="checkbox" id="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" />
<label  class="required">*Others</label>

However, this approach is not compatible with Magento’s backend processing. To display the checkbox field correctly in both the admin and customer registration forms, you should use Magento’s built-in select component:

<div class="field">
   <label for="marketattended1">San Francisco International Gift Fair</label>
   <select id="marketattended1" name="marketattended1" class="select">
      <option value="0">No</option>
      <option value="1">Yes</option>
   </select>
</div>

By using the select component with options for ‘No’ and ‘Yes’, Magento will automatically handle the checkbox functionality without any issues in saving or displaying the customer data.

Conclusion

In this post, we’ve explored a common challenge faced by Magento developers when adding custom checkbox fields to the customer entity. By understanding the underlying issue of incompatible attribute types and following best practices for using boolean attributes, you can ensure that your custom checkbox fields are correctly saved and displayed in both admin and customer forms.

Remember to always keep an eye on the consistency between the input and type values when working with EAV models in Magento. By doing so, you’ll be well-equipped to handle similar scenarios in future development projects.

For more insights into Magento customization and advanced implementation techniques, feel free to explore our comprehensive guides at Laravel Company.

Admin Configuration Orders Customers

Our network