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
)
));
Related
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?
I have a customizer section inside my wordpress theme. I made a setting and a control for an icon. I want my user to be able to choose what icon he wants. I implemented the icomoon icon font with classes like icon-home.
I made a setting and a control for that icon like this:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
'type' => 'option',
)
);
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'icon1' => 'mobile',
'icon2' => 'home',
),
)
);
and in html/php:
<span class="service-icon icon-<?php echo get_theme_mod('service1_icon', 'icon1'); ?>"></span>
But when in my browser I see the output like this:
<span class="service-icon icon-icon1"></span>
instead of:
<span class="service-icon icon-mobile"></span>
I was trying to fix it and did some stuff that were illogical to me and I fixed it.
First, I removed the type from the setting:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
)
);
Then I renamed icon1, icon2... to the actual name of the icon:
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'mobile' => 'mobile',
'home' => 'home',
),
)
);
So I have an PHP file that includes a form so that users can post jobs on my website. I want to make some fields of this form ReadOnly to the user. How?
public static function init_fields() {
if ( self::$fields )
return;
self::$fields = apply_filters( 'submit_job_form_fields', array(
'job' => array(
'job_category' => array(
'label' => __( 'Job category', 'job_manager' ),
'type' => 'select',
'required' => true,
'options' => self::job_categories(),
'placeholder' => '',
'priority' => 3
),
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4
),
I know this is probably easy to do, but for some reason I can't find how to do it.
Use the disabled attribute:
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4,
'disabled' => 'true' //html disabled input
)
This is a proprietary config file. You need to look at the code that is parsing it and converting to HTML. It may allow passing through variables like readonly, or may not.
Try passing 'readonly' => true in your array.
Remember that someone can change the value of the readonly field using an inspector like Firebug, Chrome Developer Tools, etc.
I am currently validating a URL using the Regex Pattern and it appears to be working correctly. However, if I leave the URL field blank, it should not check the Regex Validation or perhaps just return a message like "No URL given".
Here is an example of my current code I'm working with:
array(
'name' => 'programurl1',
'attributes' => array(
'type' => 'text',
'error_msg' => 'Enter Valid Program URL 1',
'label_msg' => 'Program URL 1 *'
),
'validation' => array(
'required' => true,
'filters' => array(
array(
'name' => 'StripTags'
),
array(
'name' => 'StringTrim'
)
),
'validators' => array(
array(
'name' => 'Regex',
'options' => array(
'pattern' => '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/'
)
)
)
)
)
I'm not certain how to accomplish what I am looking for when the URL field is blank.
Instead of a type text, you can use the url type. That is specifically meant to enter url values:
$this->add(array(
'name' => 'programurl',
'type' => 'Zend\Form\Element\Url',
'options' => array(
'label' => 'Program URL 1'
),
'attributes' => array(
'required' => 'required'
)
));
The url element is a special HTML5 element, see also the docs.
Zend\Form\Element\Url is meant to be paired with the Zend\Form\View\Helper\FormUrl for HTML5 inputs with type url. This element adds filters and a Zend\Validator\Uri validator to it’s input filter specification for validating HTML5 URL input values on the server.
Afaik if the browser cannot render the url input element, it just shows the text input as a fallback.
I want to develop a module that add fields to user profile in drupal 7, like phone number and CV ...
and I don't know how to do that (using Database or using fields API)
pls help me.
Any clear tutorials will be appreciated.
Try to follow the following code
$myField_name = "NEW_FIELD_NAME";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'text',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'user', // change this to 'node' to add attach the field to a node
'bundle' => 'user', // if chosen 'node', type here the machine name of the content type. e.g. 'page'
'label' => t('Field Label'),
'description' => t(''),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
)
);
field_create_instance($field_instance);
Hope this works... Muhammad.