I am trying to learn how to add fields onto a form and store them in the database. I am using the registration form for this exercise.
So far I have:
- displayed an additional field
- located relevant table in the db that stores the label (eav_attribute), names (customer_entity_varchar) and email (customer_entity)
- set is_required to 1
- displayed label next to field
My problem is that when I input data that field is not saved to the database, also I can leave it blank and the form will still be accepted. I assume this is because I added the data directly to my database (therefore bypassing other functions Magento needs to run).
I have looked around for an answer and found this, which seems to confirm my thought about needing to use a setup script for this task and I also came across this. Between the two of them I was pretty confident I could overcome this issue without any further help but I can't work out:
from link 1
customer_account_createare identified as being needed?
from link 2
what do the first and second parameters do in
$this->addAttribute()in the setup script, I can see the third parameter is the values for each column?
how is the first parameter of setData() decided?
*snippet from link 2*
<address_setup> <setup> <module>Excellence_Address</module> <class>Mage_Customer_Model_Entity_Setup</class> <!-- This is the important thing--> </setup> <connection> <use>core_setup</use> </connection> </address_setup>
$installer = $this; $installer->startSetup(); $this->addAttribute('customer_address', 'govt_id', array( 'type' => 'varchar', 'input' => 'text', 'label' => 'Govt ID No#', 'global' => 1, 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'visible_on_front' => 1 )); Mage::getSingleton('eav/config') ->getAttribute('customer_address', 'govt_id') ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address')) ->save(); $installer->endSetup();