I am creating an admin module. I have set of fields and i want to create a fieldset each of 3 fields in system configuration, i have created fields but wanted to add fieldset in it.
Any help would be appreciated. Thank you
You haven't given much information i.e Layout of your module, whether you are adding fields in code or .phtml but this is how I am adding fields to a field set:
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('form_settings', array('legend'=>Mage::helper('mymodule')->__('Module Settings')));
$newFieldset = $fieldset->addFieldset('form_settings_test', array('legend'=>Mage::helper('khaosconnect')->__('Order Settings')));
$newFieldset->addField('mysetting1', 'text', array(
'label' => Mage::helper('mymodule')->__('Setting 1'),
'class' => 'required-entry',
'required' => true,
'name' => 'mysetting1',
'value' => "val1",
'style' => 'width:500px'
));
$newFieldset->addField('mysetting2', 'text', array(
'label' => Mage::helper('mymodule')->__('Setting 2'),
'class' => 'required-entry',
'required' => true,
'name' => 'mysetting2',
'value' => "val2",
'style' => 'width:500px'
));
}
EDIT: Updated to show nested fieldsets.
Related
I would like to remove the empty or first option of list data value. I have FruitList model and it has a list, so I need to prevent from users to select all.
But now the problem is the empty option that can let user to select all Fruits, so how can I remove.
This is my code
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'header' => 'Buyer',
'name' => 'Buyer',
'value' => 'customer_name',
'filter' => $fruits
),
array(
'header' => 'Fruits',
'name' => 'fruit_id',
'value' => '$data->Buyers->FruitList->Name',
'filter' => $fruits
),
array(
'class'=>'CButtonColumn',
),
),
));
By default filters for CGridView renders dropdown with empty option to allow disabling filtering. But you can overwriting this behavior by providing your own dropdown as a filter:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'header' => 'Buyer',
'name' => 'Buyer',
'value' => 'customer_name',
'filter' => CHtml::activeDropDownList($model, 'customer_name', $fruits),
),
array(
'header' => 'Fruits',
'name' => 'fruit_id',
'value' => '$data->Buyers->FruitList->Name',
'filter' => CHtml::activeDropDownList($model, 'fruit_id', $fruits)
),
array(
'class'=>'CButtonColumn',
),
),
));
Make sure that you set default value for these filters in your model - something like this in your controller:
// ...
$model->fruit_id = FruitList::DEFAULT_ID;
$model->customer_name = FruitList::DEFAULT_ID;
if (isset($_GET['FruitList'])) {
$model->setAttributes($_GET['FruitList']);
}
$dataProvider = $model->search();
// ...
you can set condition in the dataProvider so its return you a result of all not null value.for example
$dataProvider->criteria->addCondition('fruit_id IS NOT NULL ');
I hope its work!
I have a form in magento admin panel. In the form i have checkboxes which i can select multiple options or one. The issue is i am unable to put validations for that. Because without selecting any option i can save records. My code is as in below:
$fieldset-> addField('time_ranges', 'checkboxes', array(
'label' => Mage::helper('CheckoutTime')->__('Time Ranges'),
'required' => true,
'class' => 'required-entry',
'name' => 'time_ranges[]',
'values' => array(
array(
'label' => Mage::helper('CheckoutTime')->__('Education'),
'value' => 'education',
),
array(
'label' => Mage::helper('CheckoutTime')->__('Business'),
'value' => 'business',
),
array(
'label' => Mage::helper('CheckoutTime')->__('Marketing'),
'value' => 'marketing',
),
array(
'value' => 'investment',
'label' => Mage::helper('CheckoutTime')->__('Investment'),
)
),
));
Can anyone please tell me how to add validations into this form.
Thank You
Try by changing
'name' => 'time_ranges[]'
to
'name' => 'time_ranges'
This way is correct. There were some issues in other places in my coding. That's why it didn't work early. Or else this is the correct way to do that.
I have created a custom extension just like a customer module and I want backend just like a customer.
My extension has two tables and two models.
My modules are:
Mage::getModel('custommod/reg') - just like Mage::getModel('customer/customer'), reg saves data of registration
Mage::getModel('custommod/personal') - just like Mage::getModel('customer/address'), //personal data of a reg records.
Please check the image below:
Now I am facing the problem to show the data and edit .
In Magento customer admin section, Customer edit position has multiple tabs: Account information, Address etc.
Here, Account information tab saves data in customer/customer
and Address information tab saves data in customer/address.
I like this type of section.
After a long time work i have done it ,Here the solution
The tabs.php show left panel
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('vendor_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('vendor')->__('Manage Vendor'));
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('vendor')->__('General Information'),
'title' => Mage::helper('vendor')->__('General Information'),
'content' => $this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_form')->toHtml(),
));
$this->addTab('vendor_details',array(
'label'=>Mage::helper('vendor')->__('Vendor Store Details'),
'title'=>Mage::helper('vendor')->__('Vendor Store Details'),
'content'=>$this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_storedetails')->toHtml(),
));
return parent::_beforeToHtml();
}
}
after the form.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$vendor = Mage::registry('vendor_data');
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor Registration')
));
$fieldset->addField('name', 'text', array(
'name' => 'name',
'label' => Mage::helper('vendor')->__('Name'),
'required' => true,
));
$fieldset->addField('email', 'text', array(
'name' => 'email',
'label' => Mage::helper('vendor')->__('Email'),
'required' => true,
));
$fieldset->addField('user_name', 'text', array(
'name' => 'user_name',
'label' => Mage::helper('vendor')->__('User name'),
'required' => true,
));
$fieldset->addField('password', 'password', array(
'name' => 'password',
'class' => 'required-entry',
'label' => Mage::helper('vendor')->__('Password'),
'required' => true,
));
$this->setForm($form);
$form->setValues($vendor->getData());
return parent::_prepareForm();
}
public function filter($value)
{
return number_format($value, 2);
}
}
Second form Storedetails.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Storedetails extends Mage_Adminhtml_Block_Widget_Form{
protected function _prepareForm(){
$vendorStore = Mage::registry('vendor_store_details');// new registry for different module
$form = new Varien_Data_Form();
//$form->setFieldNameSuffix('vendor_store');
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor deatsilsn')
));
$fieldset->addField('alternative_email','text',array(
'name' =>'alternative_email',
'label' => Mage::helper('vendor')->__('Alternative Email'),
'required'=> false
));
$fieldset->addField('shopname','text',array(
'name' =>'shopname',
'label' => Mage::helper('vendor')->__('Shop Name'),
'required'=> true,
'class' => 'required-entry',
));
$fieldset->addField('company', 'text', array(
'name' => 'company',
'label' => Mage::helper('vendor')->__('Company'),
'required' => true,
'class' => 'required-entry',
));
$fieldset->addField('street','text',array(
'name' =>'vendor_details[street]',
'label' => Mage::helper('vendor')->__('Street Address'),
'required'=> false
));
$this->setForm($form);
$form->addValues($vendorStore->getData());
return parent::_prepareForm();
}
}
I try to create new attribute with type select in the installer. But I don't know whether it's possible to create such an attribute without setting any options. Here is my code:
$installer = $this;
$config = array(
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'input' => 'select',
'label' => 'Theme',
'type' => 'varchar',
'apply_to' => null,
'searchable' => false,
'required' => false,
'user_defined' => 1,
'option' => array(
'values' => array()
)
);
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'custom_attr', $config);
Attribute is created but it has text type. Please help!
I have a form with multi select box:
echo $this->Form->input('emp_id', array( 'options' => array( $arr),
'empty' => '(choose one)',
'div'=>'formfield',
'error' => array( 'wrap' => 'div',
'class' => 'formerror'
),
'label' => 'Team Members',
'type' => 'select', 'multiple' => true,
'style' => 'width:210px; height:125px;'
));
I selected multiple values from this list box and click the SAVE button.
But it displays the validation message.
How can i solve this?
class TravancoDSRGroup extends AppModel {
var $name = 'TravancoDSRGroup';
var $useTable = 'dsr_group'; // This model uses a database table 'exmp'
var $validate = array(
'emp_id' => array(
'rule' => 'notEmpty',
'message' => 'The employee field is required'
)
);
}
This is the model code....
If it is possible...?
You don't have to explicitly specify
'type' => 'select'
if you set 'emps' from the controller, it will allow cake's automagic to work. just add
$this->set(compact('emps'));
Post output of debug($this->request->data) for better understanding of problem.
Have you defined hasMany or HABTM relationships to the emp ? To have multiple values saved you will have to define hasMany or HABTM relations, if you wish to save it as CSV then you will have to do the processing yourself in 'beforeSave'.