My backend login form submits with a single click of the login button. It creates an <input type="hidden" name="login-button"> element then shortly thereafter submits. On the frontend the same is created on click but never posts the data until I click the button again.
Here is a sample of the view code:
<div id="login-form" class="col-sm-12">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="col-sm-5 col-sm-offset-4 forgotPassword">
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div style="margin:auto;color:#fff;margin:1em 0;font-size:10px;">
if you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>
</div>
<div class="form-group">
<?= Html::submitButton('login', ['class' => 'btn btn-primary loginButton', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
The only difference I am seeing between the two is that there are some additional <div> tags that have been added for styling purposes. I have even removed those and I am still seeing the same issues.
Any ideas would be appreciated.
It looks like the id on the form div was causing the issue. Removing this has cleared everything up.
It was causing a conflict because it had the same id as the form.
I just want to add that usually you assign model "formName" as your form id
<?php $form = ActiveForm::begin(['id' => $model->formName()]); ?>
Related
I am facing issue with material design radio button using in yii2.
this is the material design radio button which is working perfectly
<div class="radio">
<label>
<input type="radio" name="q_option" value="Recent advances in MS">
Recent advances in MS
</label>
</div>
but when I write the same radio button in yii2 framework, the radio button dot become disappear and become non clickable
<div class="radio">
<?= $form->field($model, 'q_option')->radio(
['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS']
) ?>
</div>
please guide me. Thanks a lot in advance.
Maybe be you mean radio buttons? Single radio doesnt have mean.
//controller
$model = new Cities();
return $this->render('index', [
'model' => $model,
]);
//view <?php
use yii\bootstrap\ActiveForm;
?>
<?php $form = ActiveForm::begin() ?>
<div class="radio">
<?= $form->field($model, 'city_name')->radio(
['label' => 'Recent advances in MS', 'value' => 'Recent advances in MS']
) ?>
</div>
<?php $form::end() ?>
work well
You use $model and table_field_name. Maybe you tried use radio button list? Like that:
//view
$model = new Cities();
return $this->render('index', [
'model' => $model,
'array' => Cities::find()->all(),
]);
//controller
<?php
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
?>
<?php $form = ActiveForm::begin() ?>
<?= $form->field($model, 'city_name')
->radioList(ArrayHelper::map($array, 'id', 'city_name')) ?>
<?php $form::end() ?>
When I include if condition in update form I'm getting blank page.
Otherwise without if condition update works fine.
_form.php without if condition (this works fine)
<?= $form->field($model, 'certified')->radioList(['y'=>'YES', 'n'=>'NO']) ?>
<div class="row">
<div class="row">
<?= $form->field($modelcertificate, 'description')->dropDownList(
ArrayHelper::map(CertificateDescription::find()->all(),'description','description'),
[ 'prompt'=>'select desc',
]); ?>
</div>
<div class="row">
<?= $form->field($modelqm, 'q1')->textInput(['maxlength' => true]) ?>
</div>
</div>
For the same if I include If condition, after hitting update button blank page will be shown.
_form.php with if condition ( leads to blank page)
<?= $form->field($model, 'certified')->radioList(['y'=>'YES', 'n'=>'NO']) ?>
<div class="row">
<?php if ($model->certified == 'y') : ?>
<div class="row">
<?= $form->field($modelcertificate, 'description')->dropDownList(
ArrayHelper::map(CertificateDescription::find()->all(),'description','description'),
['prompt'=>'select desc', ]); ?>
</div>
<?php else: ?>
<div class="row">
<?= $form->field($modelqm, 'q1')->textInput(['maxlength' => true]) ?>
</div>
<?php endif; ?>
</div>
The problem was in Controller, so blank page is caused by missing return point.
For debug purposes it possible to use CRUD generated by gii, and improve it line by line to fit your personal needs.
I need Radio Button group in separate place in yii2 like in this question . I can customise the radio button like in this picture
but when I submit the form only the value of last radio is always submitted if last radio button is clicked respective value else null . I am not able to submit previous checked value.
mine form looks like
<div class="cart-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'product_id')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'size_id')->dropDownList(
ArrayHelper::map(Productsize::find()->where(['product_id'=>$id])->all (), 'product_size_id', 'product_size' ),
[ 'prompt'=>'Select size',
'onchange'=>'
$.get( "'.Yii::$app->urlManager->createUrl('cart/lists?id=').'"+$(this).val(),
function( data ) {
$( "#pricetag11" ).val(data);
$( "#pricetaghtml" ).html(data);
});
']); ?>
<?php $colors = Productcolor::find()->where(['product_id'=>$id])->all(); ?>
<h4>Price:</h4> <p id="pricetaghtml" style="color:red;"></p>
Select size to see the price
<?php echo $form->field($model, 'price_id')->hiddenInput(['id'=>'pricetag11'])->label(false)?>
<!-- here is my problem -->
<h4>Color:</h4>
<?php foreach($colors as $color):?>
<div style="background-color:<?= $color->product_color;?>;width:20px;height:20px;padding-left:3px; display: inline-block"> <?= $form->field($model, 'color_id')->radio(['value' =>$color->product_color, 'label'=>'','uncheck'=>'null']); ?></div>
<?php endforeach;?>
<!-- -->
<?= $form->field($model, 'quantity')->textInput(['type' => 'number','min'=>'0','max'=>'9999' , 'placeholder'=>'0']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
In my scenario, I have to load color (hexcode) from database table and display in form and need to save the respective code in another table using radio button.
I have tried so many ways to accomplish this task in yii2 but i am not able. i hope someone will point me to the right direction.
I guess this will work,
<?= $form->field($model, 'color_id')->radioList(
$colors,
[
'item' => function($index, $label, $name, $checked, $value) {
$return = '<div style="background-color:'.$value.';width:20px;height:20px;padding-left:3px; display: inline-block">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '">';
$return .= '</div>';
return $return;
}
]
)
->label(false); ?>
I have an Yii2 app with advanced template. There is 2 fields on my form. 1st: MaskedInput and 2nd textInput with readonly attribute.
So, I wanted to fill 2nd textInput automatically right after I have filled MaskedInput. For this I tried to use onchange. But I got following error:
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\widgets\MaskedInput::onchange
Here is my code:
<?php $form = ActiveForm::begin(); ?>
<div class="row">
<div class="col-xs-3">
<?= Html::label("Ser num")?>
<?= MaskedInput::widget(['name'=>'serNum',
'mask'=>'AA 9999999',
'onchange'=>'
$.post("index.php?r=act/actid&serNum='.'"+$(this).val(),function(data){
$("select#ser-sernum").html(data);
});
'
])?>
</div>
<div class="col-xs-3">
<?= $form->field($model, 'sernum')->textInput(['readonly'=>true]) ?>
</div>
<div class="col-xs-6">
<b id="actstatus"></b>
</div>
</div>
Try with options property:
<?= yii\widgets\MaskedInput::widget(['name'=>'serNum',
'mask'=>'AA 9999999',
'options' => [
'onchange'=>'
$.post("index.php?r=act/actid&serNum='.'"+$(this).val(),function(data){
$("select#ser-sernum").html(data);
});'
]
])?>
I have a form like this:
email
[input]
password
[input]
Login-Button
I want to eliminate the "email" and "password" text and put them inside the inputs like placeholder and also change the "login" text to "LOGIN".
This is my login ctp.
<fieldset style="background:#F44336">
<?= $this->Form->create() ?>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
<div class="forgot">
<p>Forgot Password?</p>
</div>
Your question is confusing and vague.
But I believe you are asking you dont want the value or words "Email" and "Password" to be next to the input but rather inside the input textbox?
If so, you can add HTML code inside the HTML form
<input type="email" name="email_form" placeholder="Email">
Keep in mind that is HTML 5.
In HTML 4, the traditional way would to be adding an attribute to the HTML form to email or password as value="Email..."
Above code is correct but you should use helpers.
So a better way to achieve the same task with Html helpers is:
<?= $this->Form->input('email', array('label' => false)); ?>
<?= $this->Form->input('password', array('label' => false)); ?>
It's a suggestion to make your code better which we all should focus on.