I"m having trouble with CakePHP3's Form Helper class.
When I create a text input field like this:
echo $this->Form->input('fieldname');
When the input field is "required", a label appears in bold. This is fine.
However, when I create a select field like this:
echo $this->Form->select('fieldname', [1,2,3,4,5]);
The select field is created however there is no label at all. I can add it manually using:
echo $this->Form->label('fieldname');
However in cases where the select is a required field, the font is not correct (required labels show up bold with a red * following them). I've narrowed this down to the CSS only applying to nested label tags (so when I create a label tag, it's not inside a div tag like the labels for the text inputs are).
I'd like to avoid manually inserting HTML code to achieve my desired result, any help would be appreciated!
<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => ['0' => 'Option1' , '1' => 'Option2'], 'empty' => __('(choose one)'), 'label' => __('LabelName')]);?>
or
$sizes = ['s' => 'Small', 'm' => 'Medium', 'l' => 'Large'];
<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => $sizes, 'default' => 'm', 'label' => __('LabelName')]);?>
Related
I'm editing a dropdown box. i need to use empty and selected in same dropdown.
here is my code
$this->Form->input('per', array('id'=>'per','class'=>'inputs con_field','label'=>'per :', 'type'=>'select','options'=>$per_values,'selected'=>$labrcfps['Labourcfps']['per'],'empty'=>'- - Select --'));
If i use empty it automatically takes the empty as selected value.
I'm new in cakephp but i do this with array and parameter defaults :)
like that:
$options = array(
'x' => 'Select',
1 => 'Something',
2 => 'Car',
3 => 'Train'
);
echo $this->Form->input('name', array(
'options' => $options,
'default' => 'x'
));
Maybe that will be working fine :)
Variable $options is just your options after that you can validate if name of that field has value integer or 'x'. If 'x' then deny rest of logical code
Somebody please give me ideas on this!I would like to generate multiple checkboxes with an image along with the text in the label. I have created a field called solutioncheckbox in the Contact form for Checkbox. My code is as below for creating multiple Checkboxes
<?php echo $this->Form>input('solutioncheckbox',array('label'=>false,'type'=>'select','class'=>'solution','multiple'=>'checkbox','options'=>array(1=>'WEB DESIGN',2=>'WEB DEVELOPMENT',3=>'GRAPHICS DESIGN'))) ;?>
Can I create an image along with the text in each of the labels like WEB DESIGN,WEB DEVELOPMENT etc in my form
This will get the job done for you ;)
echo $this->Form->input
(
'Model.field',
array
(
'multiple' => 'checkbox',
'options' => array('1' => $this->Html->image('cake.icon.png') . 'Text beside the image', '2' => $this->Html->image('test-error-icon.png') . 'Other text beside the image'),
'escape' => FALSE
)
);
I am new to CakePHP now I'm working on checkbox I used the following statement but it
gives check box after the label and it prints the field also.My requirement is it does not
print the field name and label should be displayed after the check box.
please help me ,
Thanks in advance
<?php echo $form->input('Model.name', array('multiple' => 'checkbox', 'options' =>
$options, 'selected' => $selected));?>
First, make sure your value is a boolean or tinyint. Otherwise, you will never get a checkbox.
Then, just build like this :
echo $this->Form->input('Model.field', array(
'type' => 'select',
'multiple' => 'checkbox',
'options' => array(
'Value 1' => 'Label 1',
'Value 2' => 'Label 2'
)
));
My solution is according to v.2.0
<?php
echo $this->Form->input('field_name', array(
'label' => 'Some label',
'selected' => $selected
/*maybe some other options*/
));
?>
if you've specified model name above, while creating the form, you dont need to use name of model . If field is boolean, you'd get the control as checkbox automatically. Alsom you can specify it in options array like
'type'=>'checkbox'
good luck!
To draw a check box you have to first configure your table in DB properly. Set these options on your field in DB:
Field Type = Tinyint
Length/Values = 1
Set Defualt = 0
and finally your view:
echo $this->Form->input('checkbox_field');
100% will work if not then set default value for your field in view:
echo $this->Form->input('checkbox_field', array('type'=>'checkbox'));
CakePHP 3.0
$this->Form->input('id', ['type'=>'select', 'multiple' => 'checkbox', 'options'=>$array]);
I have a form and i have ended it using,
echo $this->Form->end('Login');
However, i can't seem to assign it an id or class to style it and be able to reference it with jquery. Also,I want to style it with a picture and the picture has the text already in so i need the buttons value to be empty but i can't manage that either...
Any Help?
Many Thanks, Chris
***Note - this is the html it generates;
<div class="submit"><input type="submit" value="Login"/></div>
Ideally i would like to remove the div aswell but its not a necessity.
here's the solution:
$options = array
(
'label' => 'Update',
'value' => 'Update!',
'id' => 'blabla',
'div' => array(
'class' => 'glass-pill',
)
);
echo $this->Form->end($options);
Cheers! =)
I've been creating an app preparing it already to be internationalized. But when I try to do this:
echo $this->Form->input('end_date', array('label' => __('End Date'), 'dateFormat' => 'DMY', 'minYear' => date('Y'), 'type' => 'text'));\
It echoes two "End Date". I tried disabling label by setting it to null, but didn't work either. :(
How can I avoid this to happen?
Thanks
Instead of NULL, try setting it to false:
'label' => false
You can also set ALL inputs of a form to default to 'label'=>false by using:
'inputDefaults'=> array('label'=>false)
as an option of your form
For what it's worth, the __() function echoes its value by default instead of returning it. That's why you were seeing the label displayed twice. It was being displayed once because that's the value that the field name resolves to automagically. It was being displayed the second time by the __() method. In other words, your label option wasn't really overriding the automatic label.
echo $this->Form->input(
'end_date',
array(
'label' => __('Modified End Date Label', true), # note the "true" argument
'dateFormat' => 'DMY',
'minYear' => date('Y'),
'type' => 'text'
)
);
For more, see the __ documentation.