PHP Zend 2 Framework show Textarea - php

I'm creating a form using Zend2 framework, and can't figure out why a simple Textarea is not showing up on the view (below you can see my code). I've tried the type Text and it shows a standard single lined text field, but got luck with Textarea. I've also tried a non existing type, and zend throws an exception, so it seems Textarea type actually exists, and I must be missing a mandatory param or something like that. Could anyone point me in the right direction?
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
)
));
SOLVED
My bad, it looks there was an intermediate layer in the project ignoring all the Textarea fields.

I just check you code and found 2 things missing first
use Zend\Form\Element;
use Zend\Form\Form;
Which I think you have used in you file.
Another mistake was you were missing comma in the code. use this below code.
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
),
));
Good luck

Try changing your 'rows' and 'cols' value from a string to integer (remove single quotes).
'attributes' = > array(
'rows' => 10,
'cols' => 75,
);

Related

Adding a dropdown menu in Prestashop 1.7 module

I'm so beginner in Prestashop 1.7, I wanted to add a dropdown select section in my banner module to select the way to open the banner link.
but the selected value is never passed to the HTML, the code below IS passed but the one under isn't, can you please assist me?
[enter image description here][1]
array(
'type' => 'text',
'lang' => true,
'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_DESC',
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
)
array(
'type' => 'select', //select
'lang' => true,
'label' => $this->trans('Banner tab', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_TAB',
'required'=>'true',
'options' => array(
'query' => array(
array('key' => '_blank', 'name' => 'New tab'),
array('key' => '_self', 'name' => 'Same tab'),
),
'id' => 'key',
'name' => 'name'
),
'desc' => $this->trans('Please select the way to open the link.', array(), 'Modules.Banner.Admin')
)
This is how it looks in the Backoffice:
Here
You not only need to add a new field to your form but also handle saving the data from it.
Take a look at a few examples:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L122
Notice how the module author managed to save each configuration field from the form. This is what you need to do.
If you want to have access to data in your view, you have to pass it:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L244
Maybe after you added a new field, you forgot to handle the saving + passing to the view?

maxlength on input field wordpress customizer

Is it possible to put a maxlength on the input fields i use in the customizer.
Like putting some extra setting in the array : maxlength = > 50;
via :
$wp_customize->add_control( 'textblock-text-content', array(
'label' => 'Tekstblok tekst',
'section' => 'textblock_background_section',
'type' => 'textarea',
));
I couldnt find any solution, i hope anybody here can guide me to a fix.
Accoding to Customizer Objects docs, you could use the input_attrs parameter like this:
$wp_customize->add_control('textblock-text-content', array(
'label' => 'Tekstblok tekst',
'section' => 'textblock_background_section',
'type' => 'textarea',
'input_attrs' => array(
'maxlength' => 20
)
));

Jquery attr doesnt work on Yii

I'm trying to change the element value using Jquery but it's not working...
This is my widget where I have my element 'tag' which i want to change it to textField on edit...
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider->searchbyID($invoice_id),
'template' => '{items}{buttonCreateRow}{pager} ',
'id' => 'InvoiceLine-grid',
'rowTemplate' => $row_template,
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'InvoiceLine_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
'onclick'=>'editline(this)',
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]stentysproductref',
'tag' => 'laabel',
'tagHtmlOptions' => array(
'style'=>'background-color:#FFF;border-color:#FFF',
'onkeyup'=>'stentysref(this)',
'readonly'=>true
)
),
My Jquery is,
(as you can see the removeAttr works but attr doesn't)
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").attr("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeAttr("readonly");
}
Use .prop() and removeProp() which is added in jQuery 1.6, as the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").prop("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeProp("readonly");
}
API Doc for .prop()
If you are using EditableGrid widget without pointing AR model, then the row id looks like
$('#_1_'+row+'stentysproductref').
I'll take it into consideration for the future updates. Thank you.

How do I use a view helper inside a form in zend framework 2?

I have a view helper that returns an array called $this->getTypes();
I've set it up as an invokable:
'view_helpers' => array(
'invokables' => array(
'getTypes' => 'Account\View\Helper\GetTypes',
),
),
If I echo it in the view can see the array, but in the form it fails.
I would like something like:
$this->add(array(
'name' => 'type_id',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => 'Type *',
'value_options' => $this->getTypes(),
),
));
Any ideas?
The short answer is: you don't
The medium answer is: to get DB-Values into your Zend\Form\Element\Select you have to inject your DB-/Service-Layer into your Form.
The long answer is: written in my Blog post Zend\Form\Element\Select and Database Values

How do I use ZF2 regex validators within the factory pattern

Is anyone familiar with the use of ZF2 regex validators within the factory pattern?
I have taken this code from various blogs and other stackoverflow questions, but it does not seem to work.
The addition of the regex validator blocks all changes to my form from updating the database - so the validator must be failing even when I insert a number.
However, when I check
$form -> getMessages();
I get an empty array. Any insight would be appreciated.
To illustrate I use a very simple regex that, as I understand it, would block any entry character that is not a number.
$inputFilter->add($factory->createInput(array(
'name' => 'Number',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'max' => 20,
),
),
),
array(
'name' => 'Regex',
'options' => array(
'pattern' => '/^[0-9]+$',
'messages' => array(
'Invalid input, only 0-9 characters allowed'
),
),
),
)));
At a glance, Regex validator should sit inside "validators" array...

Categories