I am attempting to create several radio buttons with a specific label...
I am using the following code, however, there is no label
echo $this->Form->radio('qualify', [['value' => 1, 'text' => 'Yes'], ['value' => 0, 'text' => 'No']], ['label' => 'Qualify Only']);
Any ideas on how I can get the label to show up for these radio buttons?
<?php
$qualify = [['value'=>'0','text'=>'No'],['value'=>'1','text'=>'Yes']];
echo $this->Form->input('qualify', array(
'options' => $qualify,
'type' => 'radio',
'placeholder' => 'Qualify Only'
));
?>
This code will be able to pick any existing value in the edit view.
You can still use the $this->Form->input and put a type whether its a select or radio
<?php
$qualify = ['0' => 'No', '1' => 'Yes'];
echo $this->Form->input('qualify', array(
'options' => $qualify,
'type' => 'radio',
'placeholder' => 'Qualify Only'
));
?>
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?
In select drop down, make one particular value selected from values that are coming in drop down list Cakephp3.0. i am using below code:
$abc = 'india';
echo $this->Form->input('location_id',
['empty' =>'Please select', 'required'=>'required', 'class' => 'form-control', 'label'=>false]);
Name of countries are coming in drop down list, but i want to make specific value selected which is set as variable $abc (i.e india).
Try this code :
use the 'default' key in
$abc = array('1' => 'One','2'=> 'Two');
echo $this->Form->input('location_id',
'options' => $abc,
default' =>$abc[1],
['empty' =>'Please select',
'required'=>'required',
'class' => 'form-control',
'label'=>false]
);
where $abc[0] is the key of the item you want as selected
like this :
$options = array('M' => 'Male', 'F' => 'Female');
echo $this->Form->select('field', $options, array('default' => 'F'));
Use value option of form input helper. Like this :
$selected = 'india';
echo $this->Form->input('location_id', ['empty' =>'Please select', 'required'=>'required', 'class' => 'form-control', 'label'=>false, 'value'=> $selected]);
Suggestion - Read the docs once and then start the development. You will never get stuck at such simple problems. And refer docs first whenever you get stuck at anything.
echo $form->input('field_name', array(
'type' => 'select',
'options' => $arrayOfOptions, // typically set from $this->find('list') in controller
'label'=> 'Label name here',
'value' => $arrProjectLeaderDetails['id'], // specify default value
'escape' => false, // prevent HTML being automatically escaped
'error' => false,
'class' => 'input_select_medium'
));
In cakephp4 :
echo $this->Form->select(
'field_name', [1,2,3,4,5,6],
['empty', => '(Click to select Something']
);
Scroll down a bit from here in the docs: https://book.cakephp.org/4/en/views/helpers/form.html#options-for-select-checkbox-and-radio-controls
I am using Yiistrap. I want to modify content of model. I want to add some label, text box, drop-down (2 or more fields). I have given the code below & mentioned the region which I want to modify.
<?php $this->widget('bootstrap.widgets.TbModal', array(
'id' => 'myModal',
'header' => 'Modal Heading',
'content' => '<p>I Wnat to Modify this region</p>', /* Here I don't want only plain text i.e. <p> tag. I want to Add label as well as textbox, dropdown. please help me */
'footer' => implode(' ', array(
TbHtml::button('Save Changes', array(
'data-dismiss' => 'modal',
'color' => TbHtml::BUTTON_COLOR_PRIMARY)
),
TbHtml::button('Close', array('data-dismiss' => 'modal')),
)), )); ?>
<?php echo TbHtml::button('Click me to open modal', array(
'style' => TbHtml::BUTTON_COLOR_PRIMARY,
'size' => TbHtml::BUTTON_SIZE_LARGE,
'data-toggle' => 'modal',
'data-target' => '#myModal', )); ?>
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
Yii bootstrap widgets TbDatePicker not hiding after select a date.
<?php
echo $form->labelEx($modelRenterStatus,'moving_date');
$this->widget('bootstrap.widgets.TbDatePicker', array(
'model' => $modelRenterStatus,
'attribute' => 'moving_date',
'options' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
'autoclose' => true,
),
));
?>
what's wrong with my this code?
According to YB Docs Options are
options for the original library. This value will be JSON-encoded and
fed to bootstrap-datepicker
And looking into library docs here I can't see the options you have put and so they are invalid.
Taking example from YB site
$this->widget(
'bootstrap.widgets.TbDatePicker',
array(
'name' => 'some_date_jap',
'options' => array(
'language' => 'ja'
))
);
language is option in original library. So recheck it again!
Just to expand my answer here is one that works with my form
<?php
echo $form->datepickerRow($model, 'mode_attribute_here',array('hint'=>'',
'prepend'=>'<i class="icon-calendar"></i>',
'options'=>array('format' => 'yyyy-mm-dd' , 'weekStart'=> 1)
)); ?>
maybe it help others!!
More detail here
<?php
echo $form->labelEx($modelRenterStatus,'moving_date');
$this->widget('bootstrap.widgets.TbDatePicker', array(
'model' => $modelRenterStatus,
'attribute' => 'moving_date',
'options' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
'autoclose' => true,
),
));
?>