So my form is
class Form_Group_ShareGroup extends Form_Abstract
{
public function init()
{
$this->setAttrib('class', 'shareForm');
//Row 1
$this->addElement('select', 'groups', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Groups_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Please_Select_Groups_Share')
));
$this->addElement('select', 'users', array(
'decorators' => $this->getElementDecorators(),
'label' => Zend_Registry::get('Zend_Translate')->translate('Users_Colon'),
'style' => 'width:320px;',
'multiple' => true,
'data-help' => Zend_Registry::get('Zend_Translate')->translate('Select_Users_To_Share_Group_With')
));
//Row 2
$this->addElement('button', 'share', array(
'decorators' => $this->buttonDecorators,
'required' => false,
'ignore' => true,
'type' => 'submit',
'label' => 'Share',
'class' => 'btn primary'
));
}
}
and I want to populate some user data into "users" element.
example could be :
array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' )
How can I achieve this ?
I have use populate method but it didnt worked out.
to view the form I am using :
$usersGroup = new Form_Group_ShareGroup();
$this->view->usersGroup = $usersGroup;
Please help !
Thanks for reading .
Try this:
//$data = array('10000105' => 'aamaddy1 m aamaddy1','10000106' => 'aamaddy2 m aamaddy2' );
$usersGroup = new Form_Group_ShareGroup();
$usersGroup->getElement('users')->setMultiOptions($data);
Related
I am working on a custom Magento extension. Version: 1.9.0.1.
I have a custom Adminhtml form, here it is:
Here is the Form code:
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
$fieldset = $form->addFieldset('edit_form', array('legend'=>Mage::helper('smsnotification')->__('SMS Information')));
$statuses = Mage::getResourceModel('sales/order_status_collection')
->toOptionArray();
$statuses = array_merge(array('' => ''), $statuses);
$fieldset->addField('state', 'select',
array(
'name' => 'state',
'label' => Mage::helper('smsnotification')->__('Order Status'),
'class' => 'required-entry',
'values' => $statuses,
'required' => true,
)
);
$fieldset->addField('smstext', 'textarea', array(
'label' => Mage::helper('smsnotification')->__('SMS Text'),
'class' => 'required-entry',
'required' => true,
'name' => 'smstext',
'onclick' => "",
'onchange' => "",
'after_element_html' => '<br><small>SMS text must <b>NOT</b> be longer then 160 characters!</small>',
'tabindex' => 1
));
if ( Mage::getSingleton('adminhtml/session')->getsmsnotificationData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getsmsnotificationData());
Mage::getSingleton('adminhtml/session')->setsmsnotificationData(null);
} elseif ( Mage::registry('smsnotification_data') ) {
$form->setValues(Mage::registry('smsnotification_data')->getData());
}
// Add these two lines
$form->setUseContainer(true);
$this->setForm($form);
////
return parent::_prepareForm();
}
}
I use this code to get the customer name from the order:
$CustomerName = $observer->getOrder()->getBillingAddress()->getName();
How can I check the whole text and if it finds CustomVariable_CustomerName to replace it with the real customer name ?
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
I have a problem with TbEditedableColumn in YiiBooster 4.0.1
View:
$this->widget(
'application.extensions.booster.widgets.TbGridView',
array(
'type' => 'striped bordered',
'dataProvider' => new CActiveDataProvider('Stats'),
'columns' => array(
'pid',
array(
'class' => 'application.extensions.booster.widgets.TbEditableColumn',
'name' => 'login',
'sortable' => false,
'editable' => array(
//'model' => $model,
//'attribute' => 'login',
'url' => $this->createUrl('stats/editableSaver'),
'placement' => 'right',
'inputclass' => 'span3'
)
)
),
)
);
Controller:
public function actionEditableSaver()
{
Yii::import('application.extensions.booster.components.TbEditableSaver');
$es = new TbEditableSaver('Stats');
$es->update();
}
When I try to save the edited fields, I got this exception: Property "attribute" should be defined.
$es->attributes is empty.
How to fix that? Thanks.
From the source code, TbEditableSaver::update() obtains the attribute from a post or get parameter name:
$this->attribute = yii::app()->request->getParam('name');
$this->value = yii::app()->request->getParam('value');
//checking params
if (empty($this->attribute)) {
throw new CException(Yii::t('TbEditableSaver.editable', 'Property "attribute" should be defined.'));
}
In order for this parameter to be sent in the update request it needs to be defined in the editable array. To fix this:
'class' => 'application.extensions.booster.widgets.TbEditableColumn',
'name' => 'login',
'sortable' => false,
'editable' => array(
'name' => 'login',
'url' => $this->createUrl('stats/editableSaver'),
'placement' => 'right',
'inputclass' => 'span3'
)
I am trying to validate a multiply select using input filter, but every time I see a error. The error is "notInArray":"The input was not found in the haystack".(I use ajax but it doesn`t metter).
I will show part of my code to be more clear.
in Controller:
if ($request->isPost()) {
$post = $request->getPost();
$form = new \Settings\Form\AddUserForm($roles);//
$form->get('positions')
->setOptions(
array('value_options'=> $post['positions']));
//.... more code...
When I put print_r($post['positions']); I see:
array(0 => 118, 1 => 119)
in ..../form/UserForm.php I create the multiply element
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
and in the validation file the code is:
$inputFilter->add($factory->createInput(array(
'name' => 'positions',
'required' => false,
'validators' => array(
array(
'name' => 'InArray',
'options' => array(
'haystack' => array(118,119),
'messages' => array(
'notInArray' => 'Please select your position !'
),
),
),
),
What can be the reason every time to see this error, and how I can fix it?
By default selects have attached InArray validator in Zend Framework 2.
If you are adding new one - you will have two.
You should disable default one as follow:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'options' => array(
'disable_inarray_validator' => true, // <-- disable
),
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
And you should get rid of the additional error message.
Please let us know if that would helped you.
I had written the hide and show script for the two elements by checking checkbox in zend, but the value 1 will be sent to the function for both check and uncheck, So it only shows the element but it doesn't hides the element. how to resolve it ?
$this->addElement('checkbox', 'Change_Password',
array('decorators' => $this->elementDecoratorsTr ,'label' => 'Want to Set password ? :',
'required' => false,
'onchange' => 'passwordShow(this.value)',
'Options' => array(
'checkbx1' => 'checkbx1'),
));
$this->addElement('Password', 'User_Password',array(
'decorators' => $this->elementDecoratorsTr,
'label' => 'Password:',
'style' => 'display:none;',
'required' => false,
'filters' => array('StringTrim'),
'validators' => array(array(
'validator' => 'StringLength'))
));
$this->addElement('Password', 'Confirm_Password',array(
'decorators' => $this->elementDecoratorsTr,
'label' => 'Confirm Password:',
'style' => 'display:none;',
'required' => false,
'filters' => array('StringTrim'),
'validators' => array(array(
'validator' => 'StringLength'))
));
Here is my script function to hide and show the two elements User_Password and Confirm_Password
<script>
function passwordShow(password)
{
alert(password);
if(password)
{
$("#User_Password").show();
$("#Confirm_Password").show();
}
else
{
$("#User_Password").hide();
$("#Confirm_Password").hide();
}
}
</script>