I have the following fields in a magento adminhtml form.
On submit im expecting to grab the post, and simply dump its contents, which im doing in my saveAction.
public function saveAction()
{
if ($this->getRequest()->getPost())
{
try{
$postData = $this->getRequest()->getPost();
echo '<pre>';
print_r($postData);
exit;
the output looks as follows.
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
)
Seeing my form is defined as:
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('instance_form', array('legend'=>Mage::helper('instance')->__('Instance Filters')));
$fieldset->addField('carrier_code', 'text', array(
'label' => Mage::helper('instance')->__('Carrier service'),
'name' => 'carrier_code',
'after_element_html' => '<small>Leave blank for all Carriers.</small>',
));
$fieldset->addField('postcode', 'text', array(
'label' => Mage::helper('instance')->__('Postcode'),
'name' => 'postcode',
'after_element_html' => '<small>Leave blank for all Postcodes.</small>',
));
$fieldset->addField('sku', 'text', array(
'label' => Mage::helper('instance')->__('Sku'),
'name' => 'sku',
'after_element_html' => '<small>Leave blank for all Skus.</small>',
));
$fieldset->addField('start_date', 'date', array(
'label' => Mage::helper('instance')->__('Start Date'),
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1,
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
$fieldset->addField('aura', 'file', array(
'label' => Mage::helper('instance')->__('Upload'),
'value' => 'Uplaod',
'disabled' => false,
'readonly' => true,
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1
));
I was expecting to see output like this instead :
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
[start_date] => someValue
[aura] => anotherValue
)
am i missing something? why would say the date field, not be added to the post, like all the other text input fields?
Cheers
You're missing the name key in your addField('start_date', ..) call.
Each field of a Varien_Data_Form you want to be submittable needs a name key/value pair.
The value you assign to your field's name key is used as value for the name attribute of the corresponding <input> element when rendering the <form>.
Related
First, i'm sorry for my bad english,
im using sonata-admin bundle, and adminstrating my own Entity, when i'm creating a new item I have a block of text (the text that i write in the first input) that appears in the top of the Admin page, and it's ugly when its a big paragraph.
Lets say my first input is "Content", so when I write " This is my content " and save the item, it says "The item " This is my content" has been created succefully", how can I make another input be written in the success message
EDIT :
Here is a printscreen :
$formMapper
->add('page_mere1', 'choice', array('label' => 'Page mère 1', 'choices' => array('Podologie' => 'Podologie', 'Podz Pro'=>'Podz Pro')))
->add('page_mere2', 'choice', array('label' => 'Page mère 2', 'choices' => array('Pathologies' => 'Pathologies', 'Maladies spécifiques'=>'Maladies spécifiques')))
->add('page_mere3', 'choice', array('label' => 'Page mère 3', 'choices' => array('Pied' => 'Pied', 'Cheville'=>'Cheville', 'Jambe'=>'Jambe', 'Genou'=>'Genou', 'Hanche'=>'Hanche', 'Dos'=>'Dos')))
->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => "Antipodes\SiteBundle\Entity\Pathologie",
'fields' => array(
'titre' => array(
'field_type' => null,
'required' => false,
'label' => 'Titre.',
'locale_options' => array(
'fr' => array(
'label' => 'Titre'
),
'en' => array(
'label' => 'Title'
)
)
),
'Definition' => array(
'field_type' => null,
'required' => false,
'label' => 'Definition.',
'locale_options' => array(
'fr' => array(
'label' => 'Definition'
),
'en' => array(
'label' => 'Definition'
)
)
),
)
))
;
//.......
Thanks in advance
I'm not sure if I'm understanding you correctly, but if you want to change the OK flashbag message after an successful edit you can do this with the _toString() method in your entity.
Open your Pathologie entity and add/edit the __toString() function, example:
public function __toString() {
return $this->titre;
}
The save-flashbag would then merge the "titre"-value instead of "Definition"-value into the message.
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);
I have a plugin filter installed from https://github.com/lecterror/cakephp-filter-plugin.
How can i rename the values in the dropdown bar?
Right now I can choose between:
[ ]
[0]
[1]
What I need is:
[ ]
[Agent]
[Investor]
.
public $filters = array(
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'selectOptions' => array (
0 => 'Agent',
1 => 'Investor'
)
)
)
)
);
At the selector type I want to rename 0 to Agent and 1 to Investor.
Find it myself:
//plugincode-----> filter_form_fields
foreach ($viewFilterParams as $field) {
// Edited on 28-03-2013
// check if option type is select.
if ($field['options']['type'] == "select") {
// check for all option values ( 0,1,2,3,4 ect ) and rename it with optionNewValue
foreach ($field['options']['options'] as $optionvalue) {
$optionNewValue = $field['options']['OptionKey'][$optionvalue];
// Rename the optionvalue
$field['options']['options'][$optionvalue] = $optionNewValue;
}
}
// filtercomponent.ctp add (plugin code )
// Optionkey gives the values filter_form_fields
// use inside the controller Optionkey => array() to rename values
$options['OptionKey'] = $settings['OptionKey'];
and now you can put in the controller
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'OptionKey' => array (
0 => 'agent',
1 => 'investor'
)
)
)
);
:D:D:D:D:D
I'm trying to modify a piece of code that generates an input field using the Symfony 2 framework. The thing he creates the field with a default label equals to the name id of the field, in this case; "amount".
<?php
//++++++++++ descrizione
echo $view['form'] -> row($form["amount"], array(
//widget
"widgetArgs" => array(
"attr" => array(
'class' => 'input-small tooltipRight',
'id' => "gift_amount"
),
"tooltip"=>"gift.tooltip.amount",
"translation_domain" =>"brand"
),
"labelArgs" => array(
"label_attr" => array(
'class' => 'control-label',
)) ,"rowType"=>2
)
);
?>
How can i edit this to make it show a custom label?
You have to add the label properties:
<?php
echo $view['form']->row($form["amount"], array(
'widgetArgs' => array(
"attr" => array(
'class' => 'input-small tooltipRight',
'id' => "gift_amount"
),
'tooltip'=>'gift.tooltip.amount',
'translation_domain' =>'brand'
),
'label' => 'My ammount',
));
When adding a new group in BoonEx Dolphin, there is an HTML form that contains several input fields. Among the fields, there are Country, City, Zip/Postal Code - how can I remove those from the form?
Group/Add Group/ Group'sInfo
Here is the answer for your question. Refer this link.
edit the file "modules/boonex/events/classes/BxEventsFormAdd.php"
here you see this for country:
'Country' => array(
'type' => 'select',
'name' => 'Country',
'caption' => _t('_bx_events_caption_country'),
'values' => $aCountries,
'required' => true,
'checker' => array (
'func' => 'preg',
'params' => array('/^[a-zA-Z]{2}$/'),
'error' => _t ('_bx_events_err_country'),
),
'db' => array (
'pass' => 'Preg',
'params' => array('/([a-zA-Z]{2})/'),
),
),
delete the line:
'required' => true,
same for city and place, or you could try to delete the whole code from above
for groups the same on the file:
modules/boonex/groups/classes/BxGroupsFormAdd.php
Here is the link for more details:
http://www.boonex.com/forums/topic/Remove-Country-from-mandatory-field-in-Groups-and-Events.htm