cakephp3 form radio control access other entity value - php

I need to populate some entity value into the radio HTML code, I look
through all documentation but does not seem to be able to find any help
below is the php code, {{entity->description}} is the entity value I want to show
$this->Form->setTemplates ( [
'radioContainer' => '{{content}}'
] );
echo $this->Form->control ( 'OrderShippingMethodId',
[
'templates' => [
'nestingLabel' => '**<p>{{entity->description}}</p>**
{{input}}{{text}}',
'radioWrapper' => '{{label}}' ],
'options' => $shippingMethodsRadio,
'type' => 'radio',
'label' => false,
'type' => 'radio',
'id' => 'OrderShippingMethodId',
'legend' => false ,
'escape' => false
] );
it generate the below html code, the <p></p> is not showing the entity description value
Shipping
as can be seen in the bold code above, the entity->description value cannot be read
out, seem that the only value the form->control can read out from the
entity is text, value. is there anyway to access other value in the entity
in the controller method, to populate $shippingMethodsRadio
$this->set('shippingMethodsRadio' => $shippingMethods->extract('radio'));
the $shippingMethods, will contain a collection of the entity shippingMethod, I want to read other value like description property in the entity into the radio control, the radio property in the shippingMethod return an array contains value, text, description property of the entity to populate the radio control
thank you

Related

FormHelper::input() creates a drop-down select if fielname has the "_id" suffix

I have the following line of code on a CakePHP view:
<?php
echo $this->Form->input(
'person_id',
array(
'label' => false,
'div' => false,
'class' => 'form-control search-person'
)
);
?>
I want to create a text input with this line of code, but if the field name has the suffix _id, the rendered HTML changes from a text field to a drop-down select.
If I change the prefix to anything else, for example person_idd or abc_idd, it renders a text input, but if the field name ends with _id suffix, it renders a drop-down select, which doesn't allow me to write anything.
Is this some CakePHP feature? How can I avoid this behavior and produce a text input with a field ending with the _id suffix?
It's a CakePHP feature:
This method will automatically inspect the model field it has been supplied in order to create an appropriate input for that field.
Taken from Cookbook 2.x: FormHelper: Creating form elements.
To get a text input, add 'type' => 'text' to the options array:
<?php echo $this->Form->input('person_id', array(
'type' => 'text',
'label' => false,
'div' => false,
'class' => 'form-control search-person'
)); ?>

Symfony2- get data of auto populated drop down

I'm having two dropdowns which are not dependent on any entity. When I select the value of first one an ajax function is called to populate the second one which is done perfectly. But, the form after submission, always returns
type_name: ERROR: This value is not valid
My form looks like:
->add('type', 'choice', array(
'empty_value' => "Select",
'choices' => array(
1 => 'One',
2 => 'Two'
)
))
->add('type_name', 'choice', array(
'empty_value' => "Select",
'choices' => array(
),
))
This is because Symfony needs to know the choices beforehand in order to validate them correctly. Currently you are indicating that no choices are valid for your dropdown type_name as you are passing an empty array as choices.
Please check this answer for a detailed guide on how to implement dynamic choices and choice validation: https://stackoverflow.com/a/13374841/606104

How to transform the tab of selected values in a select(html) into a field in symfony2

i have to work on a project with symfony2.
I have to create a form with many select input. These select inputs can have more one value selected.
I want to insert all the selected values in one field like that :
value 1
value 2
value 3
result => value1;value2;value3
So I don't have to have a one-to-many relation.
How can I do that, knowing each select input is generated thanks to their entity ?
and when I want to submit i have this error :
Warning: oci_bind_by_name(): Invalid variable used for bind in [...]/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php line 156
->add('cod_rom','entity',array(
'label' => 'Codes romes :',
'class' => 'xxxxListeBundle:CodeRome',
'expanded' => false,
'multiple' => true,
'required' => false,
'property' => 'libelle'
))

Magento custom dependent category attributes

I have some custom attributes for my project.
Attribute1 : Use in home page sidebar(yes/no)
if it is yes show the below attribute.
Attribute2 : Browse image
I want to add attribute2 based on the attribute1. Only when the Use in Home Page Sidebar is enabled , my new attribute will be shown below of the current. I.e., it will be a dependent attribute. Does somebody know the script for adding dependent attributes in Magento?
Previously i added custom attributes by
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'use_home_page_side_bar', array(
'group' => 'General',
'input' => 'select',
'type' => 'int',
'label' => 'Use in Home Page Sidebar',
'backend' => '',
'source' => 'eav/entity_attribute_source_boolean',
'visible' => true,
'required' => false,
'visible_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
Like this script, is there any script for adding dependent attributes?
If you are working on admin forms, then a class exists for automatically hiding elements when the value of fields change.
Below is an example which shows field dependency.
$form = new Varien_Data_Form();
$form->addField('yesno', 'select', array(
'label' => $this->__('Yes or No?'),
'values' => Mage::model('adminhtml/system_config_source_yesnocustom')
->toOptionArray(),
));
$form->addField('custom_value', text, array(
'label' => $this->__('Other'),
));
// Append dependency javascript
$this->setChild('form_after', $this->getLayout()
->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap('yesno', 'yesno')
->addFieldMap('custom_value', 'custom_value')
->addFieldDependence('custom_value', 'yesno', 2) // 2 = 'Specified'
);
You need to map every field name to an element ID. You can add as many field mappings and field dependencies in this way as you wish.
I have created simple category attribute dependency by adding new input renderer for attribute. It is working this way:
You have several attributes:
– my_attribute
– my_attribute_text
– my_attribute_select
Note that they all start from my_attribute.
First attribute has boolean type. When it is set to true – other attributes that start from my_attribute is visible.
Source - https://github.com/elpas0/category_dependence
Description - http://nwdthemes.com/2015/02/20/magento-category-attributes-dependency/

how to use Yii Eselect2 to save more data?

I use Eselect2 Yii extension to give users multiple choice but only last choice is submitted via POST. Why?
This is my html, in which I also tried to manage all choices with array but without success
<pre>echo $form->labelEx($model,'city_id');
$this->widget('ext.select2.ESelect2', array(
'name' => 'Form[field]',
'data' => City::model()->getCitie`enter code here`s(),
'options' => array('width' => '30%','allowClear'=>true),
'htmlOptions'=>array(
'options'=>array(''=>array('value'=>null,'selected'=>null, 'name'=>'field'),),
'multiple'=>'multiple',
)
));
</pre>
I tried to specify 'name' field as single field and as an array but I have the same problem: only last value is sended.
You should simply use an array :
Instead of
'name' => 'Form[field]',
You should try :
'name' => 'Form[field][]',

Categories