I've got a problem with the name of displayed field's value. In my FormType i have something like below:
$builder->add(
'level',
'entity',
array(
'class' => 'AppBundle:Level',
'label' => false,
'property' => 'name',
'mapped' => false,
'attr' => array(
'class' => 'none'
)
)
);
And insteed of property name, I would like to display my own result of toString() method. How can I do this?
Related
Env: Symfony2 2.7 / Propel 1.6
I've created a choice form type like that:
$builder->add('mychoice', 'model', array(
'class' => 'Foo\\Bar',
'query' => FooBarQuery::create()->filterBySomething(true),
'group_by' => 'example',
'property' => 'title',
'multiple' => false,
'expanded' => false,
));
The rendering choice list is ok with good optgroup select options but the title's property is not displayed - id's property instead. If I remove the group_by option, the title property is well displayed.
What's wrong?
Would this work?
$builder->add(
'mychoice',
'entity',
array(
'class' => 'Foo\\Bar',
'choice_label' => 'title',
'multiple' => false,
'expanded' => false,
)
);
Set the type to entity and add a choice_label property and the property you want to be displayed.
I have this builder at FormType class:
$builder
->add('fkTblSources', 'entity', array(
'class' => 'BlaBlaBundle:TblSources',
'property' => 'name',
))
->add('save', 'submit');`
This form shows "fkTblSources" as name of row. I need to put this name because it is the field name of the entity "TblTicket" that i want to create with this form.
How can I change this name?
Ok, it's easy, sorry.
Name of field is changed by 'label' option.
->add('fkTblSources', 'entity', array(
'class' => 'BlaBlaBundle:TblSources',
'property' => 'name',
'label' => 'name for field here'
))
Hi I am new in zend framework.
I want to set ready only property on input box in zend Form.
example as we do in html
<input type ="text" readonly="readonly" />
this is my zend code:
$this->addElement('text', 'name', array(
'label' => '',
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:338px'),
'autocomplete' => 'off',
'decorators'=>Array(
'ViewHelper',
'Errors',
),
help mee
Try this
$this->getElement('text')->setAttrib('readonly', 'readonly');
Try something like this:
$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true')));
In ZF2 you can create a form by extending Zend\Form and then add form element in the constructor. there you can set the attributes as follows.
use Zend\Form\Form;
class MyForm extends Form {
public function __construct() {
$this->add(array(
'name' => 'name',
'type' => 'Text',
'attributes' => array(
'id' => 'name',
'class' => 'form-control',
'readonly' => TRUE,
),
'options' => array(
'label' => 'Name : '
)
));
}
}
I want to make custom form in magento with two section like (two green box)
Also I wand to make three fields instead of one like
I have make code like
protected function _prepareForm() {
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('slider_form', array('legend' => Mage::helper('slider')->__('Slider information')));
$fieldset->addField('link_title', 'text', array(
'label' => Mage::helper('slider')->__('Link Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'link_title',
));
$fieldset->addField('link', 'text', array(
'label' => Mage::helper('slider')->__('Link'),
'class' => 'required-entry',
'required' => true,
'name' => 'link',
));
$fieldset->addField('content', 'text', array(
'label' => Mage::helper('slider')->__('Text'),
'class' => 'required-entry',
'required' => true,
'name' => 'content',
));
....
....
}
Can anybody help!!!
I'm trying to add filters for my form elements
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
'required' => true,
),
'options' => array(
'label' => 'Name',
),
'filters' => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags'),
)
));
but I still can add some tags in this element, what am I doing wrong?
Create two classes one for form another for filter and set filter for your form.
$form = new Form\CommentForm();
$form->setInputFilter(new Form\CommentFilter());
return $form;
for more info see https://github.com/nsenkevich/comment/tree/master/Comment