I'm using an example of bootstrap-datetimepicker in my codeigniter project.
I create a form with only the datetimepicker input.
view:
<?php // Change the css classes to suit your needs
$attributes = array('class' => '', 'id' => '');
echo form_open('/calendario/nadevent/', $attributes); ?>
<div class="form-group">
<label for="reservationtime">Fecha:</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="text" name="reservationtime" id="reservationtime" class="form-control" value="<?php echo set_value('reservationtime') ?>" />
</div>
</div>
<?php echo form_submit( 'submit', 'Submit','class="btn btn-default"'); ?>
<?php echo form_close(); ?>
JS:
$('#reservationtime').daterangepicker({timePicker: true, timePickerIncrement: 30, format: 'DD-MM-YYYY hh:mm:ss', timePicker12Hour: false, separator: '/'});
The datepicker works fine but when i submit the form, I want to format the data and split into an array:
Controller:
$this->form_validation->set_rules('reservationtime', 'reservationtime', '');
$array = explode('/',set_value('reservationtime'));
Then I try to insert the values:
form_data = array(
'start' => $array[0],
'end' => $array[1]
;
But if I print the array, its empty:
Array ( [start] => [end] => )
Wha'ts wrong with the code?
Thanks for the help :)
You really not getting data from your form, can you dump the $_POST?
Related
I've installed a plugin and I'm happy with it- until it comes to the password field section of the registration form. For some inexplicable reason the password is displayed as text upon entry, forcing the user to first actively press the "hide password" button to hide it. So by default the field input is displayed as "text" on screen and not "password". However, here is the code...
function bp_nouveau_signup_form( $section = 'account_details' ) {
$fields = bp_nouveau_get_signup_fields( $section );
if ( ! $fields ) {
return;
}
foreach ( $fields as $name => $attributes ) {
if ( 'signup_password' === $name ) {
?>
<label for="pass1"><?php esc_html_e( 'Choose a Password (required)', 'buddypress' ); ?></label>
<div class="user-pass1-wrap">
<div class="wp-pwd">
<div class="password-input-wrapper">
<input type="password" data-reveal="1" name="signup_password" id="pass1" class="password-entry" size="24" value="" <?php bp_form_field_attributes( 'password', array( 'data-pw' => wp_generate_password( 12 ), 'aria-describedby' => 'pass-strength-result' ) ); ?> />
<button type="button" class="button wp-hide-pw">
<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
</button>
</div>
<div id="pass-strength-result" aria-live="polite"><?php esc_html_e( 'Strength indicator', 'buddypress' ); ?></div>
</div>
<div class="pw-weak">
<label>
<input type="checkbox" name="pw_weak" class="pw-checkbox" />
<?php esc_html_e( 'Confirm use of weak password', 'buddypress' ); ?>
</label>
</div>
</div>
... as you can see it is already set to <input type="password" .... So it doesn't make sense to an amateur like me.
The... <?php bp_form_field_attributes( 'password', array( 'data-pw' => wp_generate_password( 12 ), 'aria-describedby' => 'pass-strength-result' )... simply autogenerates and fills the field with an autogenerated password. When using this part it would of course make sense to display the autogenerated password as text first, but that wont be the case for me.
I'm trying to achieve a default setup, that hides the key inputs on screen by default upon password-entry, instead of the other way around like it is now.
All the help is appreciated!
I set the form parameters:
<?
$form = ActiveForm::begin([
'id' => 'activeForm',
'action' => 'javascript://',
]);
$checkboxTemplate = '<div class="checkbox">{labelTitle}{beginLabel}{input}<span class="slider round"></span>{endLabel}{error}{hint}</div>';
echo $form->field($aclForm, tbl_RbacActions::IS_DEVELOPMENT)
->checkbox([
'labelOptions' => ['class' => 'switch'],
'template' => $checkboxTemplate
]);
?>
As a result, it still turns a standard form with standart classes:
<form id="Index-form" class="row col-12 no-gutters" action="javascript://" method="post">
<input type="hidden" name="_csrf-frontend" value="Lo7lVHTJ9wcN5rdfjK-b7AgW8L4OHEaqI9IsVofZPOl3yKkFBJqAQz-i-y7H3-mdMUmY-H1RcMRBhkU01-F2oA==">
<div class="form-group field-aclform-is_development required">
<input type="hidden" name="AclForm[is_development]" value="0">
<label class="switch">
<input type="checkbox" id="aclform-is_development" name="AclForm[is_development]" value="1" template="{input}{beginLabel}{labelTitle}{endLabel}{error}"> Is Development</label>
<div class="help-block"></div>
</div>
</form>
Why is it adding the template as the input attribute?
You haven't provided the HTML template that you are trying to follow or integrate here in the checkbox, but regarding the template being added as the attribute of the input field is quite logical as you are passing it as the option of the checkbox rather than the field option.
You need to provide the template as an array to the third parameter option of the field see below
<?php
$form = ActiveForm::begin(
[
'id' => 'activeForm',
'action' => 'javascript://'
]
);
$checkboxTemplate = '<div class="checkbox">{labelTitle}{beginLabel}{input}<span class="slider round"></span>{endLabel}{error}{hint}</div>';
echo $form->field(
$aclForm,
tbl_RbacActions::IS_DEVELOPMENT,
[
'template' => $checkboxTemplate
]
)->checkbox(
[
'labelOptions' => ['class' => 'switch']
]
);
I use kartik/GridView. In my database, I have following record using widget of \dosamigos\ckeditor\CKEditor in _form.php:
<p>ist gewöhnungsbedürftig aber halt auch kompetent</p>
Any ideas how to outline this record in GridView without HTML-tags, just plain text like this:
ist gewöhnungsbedürftig aber halt auch kompetent
Here is my DetailView:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
?>
<div class="bewerber-view">
<div class="row">
<div class="col-sm-9">
<h2><?= Html::encode($model->id) ?></h2>
</div>
</div>
<div class="col-lg-1">
<?php
$gridColumn = [
.
.
'beurteilung_persoenlich:ntext', //contains upper record
.
.
];
echo DetailView::widget([
'model' => $model,
'attributes' => $gridColumn
]);
?>
</div>
got solution by my own:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
?>
<div class="bewerber-view">
<div class="row">
<div class="col-sm-9">
<h2><?= Html::encode($model->id) ?></h2>
</div>
</div>
<div class="col-lg-1">
<?php
$gridColumn = [
.
.
'beurteilung_persoenlich:html', //contains upper record
.
.
];
echo DetailView::widget([
'model' => $model,
'attributes' => $gridColumn
]);
?>
</div>
will solve my problem as described.
Happy Coding
this worked for me
'your_attritube_name:html'
I want to use the simple form tag & element like
<form name="formname" action="" method="post">
<input type="text" name="title" value="" />
</form>
I want to validate all fields on client side & server side using yii model.
Model validations can easily apply with activeform but i don't want to use activeform.
Any easy way to validate the form fields on client & server both sides?
Use beginForm() method. And try something like below.
use yii\helpers\Html;
<?php $form = Html::beginForm()([
'method' => 'post',
'name' => 'formname',
]); ?>
<?= Html::textarea->textarea(['rows' => 6, 'name'=>'title'])->label(false) ?>
<div class="form-group">
<?= Html::submitButton('POST', ['class' => 'btn btn-primary']) ?>
</div>
<?php Html::endForm() ?>
and then in your model
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// $model->addRule(['fieldname'], 'string', ['max' => 50]);
}
i generate radio buttons using Yii
the code looks like
<span class="gender">
<?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'male')); ?>
</span>
<span class="gender">
<?php echo CHtml::activeRadioButton($model,'gender',array('value' => 'female')); ?>
</span>
It's generate next HTML code
<span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">
<input value="male" class="male" name="web\models\register[gender]"id="web\models\register_gender" type="radio"></span>
<span class="gender">
<input id="ytweb\models\register_gender" type="hidden" value="0" name="web\models\register[gender]">
<input value="female" class="female" name="web\models\register[gender]" id="web\models\register_gender" type="radio">
</span>
when i get POST from this form, if i checked female it returns female, but if i cheked male it returns 0. I think it is because of identical inputs ids. But how can i avoid it?
You can configure activeRadioButton to not output the "guard input" with value 0. Do this by passing the parameter 'uncheckValue' => null as part of your options array:
echo CHtml::activeRadioButton($model,'gender',
array('value' => 'male', 'uncheckValue' => null));
echo CHtml::activeRadioButton($model,'gender',
array('value' => 'female', 'uncheckValue' => null));
That said, using activeRadioButtonList is the best choice here. You can configure its template parameter to specify your custom HTML:
$genders = array('male' => 'male', 'female' => 'female');
$options = array(
'template' => '<span class="gender">{input</span>',
'uncheckValue' => null,
);
echo CHtml::activeRadioButtonList($model, 'genger', $genders, $options);