how to make hyperlink to label in zf2 - php

I want to make a hyperlink of label in zend form. I agree to the Terms and Privacy policy make terms and condition to be link.
My code is:-
$this->add(array(
'type' => 'Checkbox',
'name' => 'agreeterms',
'options' => array(
'label' => 'I agree to the Terms and Privacy policy',
'use_hidden_element' => true,
'checked_value' => 1,
'unchecked_value' => 'no',
'id'=>'term_and_condition',
),
));

You can split label and input field in the view:
$this->formLabel($this->form->get('agreeterms'));
$this->formText($this->form->get('agreeterms'));
Then you can wrap the ... around it.

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
)
));

Readonly form fields

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.

Yii: localization in Navbar with images

It would be nice to have a Dropdown menu with several flags.Is there a way to show a image like a Flag in the navigation when I use twitter-bootstrap?
If I select one flag, the language and the flag should change.
I can show the bootstrap supported Icons but they contain no flags.
I hope some can help me. below is my navigation.
$this->widget('bootstrap.widgets.TbNavbar', array(
'type' => 'null', // null or 'inverse'
'brand' => '<img src="http://localhost/images/logo.gif">',
'brandUrl' => 'localhost',
'collapse' => true, // requires bootstrap-responsive.css
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'type' => 'pills', // '', 'tabs', 'pills' (or 'list')
'items' => array(
array('label' => 'Home', 'url' => array('/site/index')),
array('label' => 'user create', 'url' => array('/account/user/create')),
array('label' => 'Contact', 'url' => array('/site/contact')),
array('label' => 'User', 'url' => array('/account/user/index')),
),
),
array(
'class' => 'bootstrap.widgets.TbMenu',
'type' => 'pills', // '', 'tabs', 'pills' (or 'list')
'htmlOptions' => array('class' => 'pull-right'),
'items' => array(
/**Added to show, that here should appear the flag*/
array('label' => '','htmlOptions'=> array('src'=>'http://localhost/images/german.png'), 'url' => ''),
array('label' => 'Sign in', 'url' => array('/account/signup/login'), 'visible' => Yii::app()->user->isGuest),
array('label' => 'Sign up', 'url' => array('/account/signup/registration'), 'visible' => Yii::app()->user->isGuest),
array('label' => Yii::app()->user->name , 'url' => '#', 'items' => array(
array('label' => 'Action', 'url' => '#'),
array('label' => 'Another action', 'url' => '#'),
array('label' => 'Something else here', 'url' => '#'),
'---',
array('label' => 'Logout', 'url' => array('/account/signup/logout')),
),'visible' => !Yii::app()->user->isGuest),
),
),
),
));
As you noticed, you'll need flag icons to start with. You could, for example, use these. You may or may not need to modify the returned CSS a little to suit your needs.
Next you need to create the switch-URLs. This essentially boils down to having the current URL AND the language selection as get parameter. Create a canonical link for the site you are currently on and attach ?lang=<target>. Another approach would be to simply attach the switch part to the current URL and use that instead. I outlined something like that here.
Next you need to make sure your application can actually handle localization. I have no idea how far along that road you are yet, so you may want to read this. To actually have the languages switch on request you can do the following in protected/components/Controller.php
public function init() {
parent:init();
if (null === Yii::app()->user->getState('lang') || null !== Yii::app()->request->getQuery('lang', null)) {
Yii::app()->user->setState('lang', Yii::app()->request->getQuery('lang','defaultLanguage'));
}
Yii::app()->setLanguage(Yii::app()->user->getState('lang'));
}
This way, wherever you are, the language gets set based on the get parameter and persists as long as the session exists. You may even want to replace 'defaultLanguage' with a call to a function that determines a default value e.g. based on the user agent string of the browser or the visitor's IP.
To generate the language files you need/want take a look at this.
To create the necessary links inside the menu you can either create a function returning the appropriate array or switch the values such as label and url with a ternary operator, e.g. 'label' => ('en' == Yii::app()->language) ? 'Switch to Spanish' : 'Switch to English'. However, this only properly works with binary decisions. If you want to offer more languages you should consider a different approach, such as the function I mentioned.

Zend Form Validate URL

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.

Categories