Yii2 kartik datetime picker widget doesn´t function? - yii2

I wanted put yii2 kartik datetimepicker into a reservation room form, but datepicker doesn´t function.
Im sure , i have use kartik/datetime/DateTimePicker; at the top of code.
This is my code for reservation form. Its not complete, but i want test posting date.
<div class="form-group">
<label> Booked room from </label>
<?php
echo DateTimePicker::widget([
'name' => 'date_in_modal_1',
'options' => ['placeholder' => 'Date and time...'],
'pluginOptions' => ['autoclose' => true]
]);
?>
</div>
<div class="form-group">
<label> Booked room to </label>
<?php
echo DateTimePicker::widget([
'name' => 'date_in_modal_2',
'options' => ['placeholder' => 'Date and time...'],
'pluginOptions' => ['autoclose' => true]
]);
?>
</div>
<input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />
<button type="submit" class="btn btn-primary">Add</button>
I using the same code in index view and this work. The inputs shows, but if i click, the form with date pick and time pick doesn´t show. Can someone help me with this problem?
Thanks u all.

Related

Input type file activeform Yii2 generate another input type hidden

I have some problem when using activeform type file. When i try to send my input in registration controller the validation from model always return it false because there is input type file that empty. After i checking from html inspect elements, it turns out that the form I created on the register page generates a new input on it with the type hidden and the same name. I still can't understand why it can generate another input type hidden and input post in controller read from that input type hidden
this is my activeform:
<?php $form = ActiveForm::begin(['id' => 'form-signup', 'action' => '/site/register/userregister', 'options' => ['enctype' => 'multipart/form-data'], 'method' => 'post' ]); ?>
<?= $form->field($model,'email')->textInput()->input('email', ['placeholder' => "Email"])->label(false) ?>
<?= $form->field($model,'photofile',
['options' => ['class' => 'form-group']])
->fileInput([])
->label('Photo file<br/><span style="font-size:12px;font-style:italic;">(Max. size 1 MB, Allowed type: .jpg, .jpeg, .png)</span>') ?>
<?= $form->field($model,'resumefile',
['options' => ['class' => 'form-group']])
->fileInput([])
->label('Resume file<br/><span style="font-size:12px;font-style:italic;">(Max. size 1 MB, Allowed type: .doc, .docx, .pdf)') ?>
<div class="form-group">
<?= Html::submitButton('Sign Up', ['class' => 'btn btn-sign', 'type' => 'submit']) ?>
</div>
<h6 class="mt-3">Have an account? <a class="font-weight-bold" href="<?= Url::to(['login/userlogin']) ?>">Sign In</a></h6>
<?php ActiveForm::end(); ?>
this my controller :
public function actionUserregister()
{
$model = new SignupModel();
if (Yii::$app->request->isPost) {
$input = Yii::$app->request->post('SignupModel');
echo "<pre>";var_dump($input);exit;
}
}
this is function in to validate rule input:
public function rules()
{
return [
['photofile', 'required'],
['photofile', 'file', 'extensions' => 'jpg,jpeg,png', 'maxSize' => 1024 * 1024 * 1],
['resumefile', 'required'],
['resumefile', 'file', 'extensions' => 'pdf,doc,docx', 'maxSize' => 1024 * 1024 * 1 ],
];
}
and this is what i see in inspect elements:
<div class="form-group field-signupmodel-photofile required">
<label class="control-label" for="signupmodel-photofile">Photo file</label>
<input type="hidden" name="SignupModel[photofile]" value> //here is the problem
<input type="file" id="signupmodel-photofile" name="SignupModel[photofile]" aria-required="true">
<p class="help-block help-block-error"></p>
</div>
<div class="form-group field-signupmodel-resumefile required">
<label class="control-label" for="signupmodel-resumefile">Resume file</label>
<input type="hidden" name="SignupModel[resumefile]" value> //here is the problem
<input type="file" id="signupmodel-resumefile" name="SignupModel[resumefile]" aria-required="true">
<p class="help-block help-block-error"></p>
</div>
what's wrong with my code above?

Custom data attribute need Dynamic Values using Yii2

Using Yii2 Framework, Get data from ArrayHelper::map(), I'm not able to get dynamic data
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="1" data-serviceid="id" type="checkbox">
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="2" data-serviceid="id" type="checkbox">
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="3" data-serviceid="id" type="checkbox">
<?= $form->field($model, 'services')->checkboxList(ArrayHelper::map($activeServiceModels, 'id', 'name'), ['itemOptions' => ['class' => 'services-checkbox','data-serviceid'=>'id']])->label('Select Service(s):'); ?>
I need Output
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="1" data-serviceid="1" type="checkbox">
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="1" data-serviceid="2" type="checkbox">
<input class="services-checkbox" name="SubscriptionPackage[services][]" value="1" data-serviceid="3" type="checkbox">
update your code like below
<?=
$form->field($model, 'services')->checkboxList(ArrayHelper::map($activeServiceModels, 'id', 'name'), ['class'=>"btn-checkbox",
'item' => function($index, $label, $name, $checked, $value) {
return "<label class='col-md-4'><input type='checkbox' data-serviceid="1" {$checked} name='{$name}' value='{$value}'>{$label}</label>";
}
]);
?>
add your class 'class'=>"btn-checkbox" into the array.
and you can debug more inside the item callback function for customization.
You can use item callable function to render each checkbox item, eg:
$form->field($model, 'name')->checkboxList(ArrayHelper::map($models, 'id', 'name'), [
'itemOptions' => ['class' => 'services-checkbox','data-serviceid'=>'id'],
'item' => function ($index, $label, $name, $checked, $value) {
return Html::checkbox($name, $checked, ['data-serviceid' => $value, 'value' => 1]) . Html::label($label);
}
])->label('Select Service(s):');

Is it possible to allow checkboxes to be checked by clicking on the label when it has a hidden field on top of it?

I have a label with a checkbox and a hidden input in it.
Without the hidden input, I was able to click on the label to check the checkbox, but with the hidden input on top of it, I can't (Except on Chrome).
Is there anyway around this without moving the hidden input (It is crucial that the hidden input is inside the label and on top of the checkbox)?
My JsBin: http://jsbin.com/kovipaxu/7/edit
Why is it crucial that the hidden field has to be inside the label and on top of the checkbox?
This is because I'm using CakePHP's form helper.
Input Options
$checkbox_options = array(
'label' => false,
'div' => false,
'type' => 'checkbox',
'class' => false,
'hiddenField' => true
);
Form:
<div class="checkbox">
<label>
<?php echo $this->Form->input('field', $checkbox_options); ?>
My Label Here
</label>
</div>
The above form will output:
<div class="checkbox">
<label>
<input name="data[FakeModel][field]" value="0" type="hidden">
<input name="data[FakeModel][field]" value="1" checked="checked" type="checkbox">
My Label Here
</label>
</div>
If there is a way to move the hidden input below the checkbox using CakePhp's form helper that would be great! But unfortunately I don't think that's possible, I went through the document and couldn't find a way.
Wow about this. Its working on Firefox
$checkbox_options = array(
'label' => 'My level here',
'div' => false,
'type' => 'checkbox',
'class' => false,
'hiddenField' => true
);

Showing html radio buttons using Perl?

I want to show 2 radio buttons used to select the gender of a student. When I try to set a variable using the CGI Perl module to produce html code for these radio buttons, only the radio selection text is showing, not the buttons:
$cInput_form .= $q->div({-class => 'control-group'},
$q->label({-class => 'control-label', -for => 'gender'}, "Gender:"),
$q->div({class => 'controls'},
$q->span({class => 'span12'},
$q->label({-class => 'blue'},
$q->radio_group({-id => 'gender',name => 'gender', -values => ['M','F'], -labels => \%labels, -default => $cGender, 'true'}), $q->span({-class => 'lbl'})))));
When I use the "Insepect element" tool in my web browser the html I see is:
<div class="control-group">
<label class="control-label" for="gender">Gender:</label>
<div class="controls">
<span class="span12">
<label class="blue">
<label>
<input type="radio" name="gender" value="M" checked="checked" id="gender" true="">
Male
</label>
<label>
<input type="radio" name="gender" value="F" id="gender" true="">
Female
</label>
<span class="lbl"></span>
</label>
</span>
</div>
</div>
I think the problem is that <span class = 'lbl'> is not in the right place, but I don't know where else it should be. Please help me.
I think the issue might be that you are grouping the radio_group within unnecessary label groups. This page shows code similar to your situation for wanting to create a gender selection radio button group.
Try changing your code to(reformatted to make it a little more readable):
$cInput_form .= $q->div({-class => 'control-group'},
$q->label({-class => 'control-label',
-for => 'gender'}, Gender:"),
$q->radio_group({-id => 'gender',
name => 'gender',
-values => ['M','F'],
-labels => \%labels,
-default => $cGender,
'true'}),
);
This is untested but I think gets across the point, just be careful when grouping 1 section inside another. Hope it helps!

how to modify parameters like (style , class ..) in cakephp input?

in cakephp
echo $this->Form->input('email', array('type' => 'email'));
will render
<div class="input email">
<label for="UserEmail">Email</label>
<input type="email" name="data[User][email]" value="" id="UserEmail" />
how to make this like that
<input type="email" name="data[User][email]" value="" id="UserEmail" class="input_class" style="some:style;" />
Just add a "class" and/or "style" argument to your options array.
echo $this->Form->input('email', array('type' => 'email', 'class' => 'input_class', 'style' => 'some:style' ));
See the the FormHelper documentation for a list of all options.
if you need only input without lable you can also try in this way
echo $this->Form->input('email', array('type' => 'email','div'=>false, 'class' => 'input_class', 'style' => 'some:style' ));