Helli i have simple form, which inserting data in my table, the problem is that i don't know how to: 1)get String value of selected dropdownlist item; 2)get String value of selected radio element 3)get smthng like String arrray of selected checkboxes; Here is the form
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'first_name') ?>
<?= $form->field($model, 'last_name') ?>
<?= $form->field($model, 'gender')->radioList([
1 => 'Male',
2 => 'Female'
]) ?>
<?= $form->field($model, 'faculty')->dropdownList([
1 => 'Faculty of Information Technology',
2 => 'Faculty of Math Science',
3 => 'Faculty of Ukrainian Literature',
4 => 'Faculty of Health'
]) ?>
<?= $form->field($model, 'languages')->checkboxList([
1 => 'Java',
2 => 'C++',
3 => 'C#',
4 => 'Python',
5 => 'PHP',
6 => 'Java Script'
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
ActiveRecord class
class Users extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'users';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['first_name', 'last_name', 'gender', 'faculty', 'languages'], 'required'],
[['first_name', 'last_name'], 'string', 'max' => 15],
[['gender'], 'string', 'max' => 7],
[['faculty'], 'string', 'max' => 20],
[['languages'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'first_name' => 'First Name',
'last_name' => 'Last Name',
'gender' => 'Gender',
'faculty' => 'Faculty',
'languages' => 'Programming Languages',
];
}
public static function primaryKey()
{
return ['customer_id','group_id'];
}
}
So problem is that values that inserted in db after form accepted is indexes of selected values, but i need values
Aucun commentaire:
Enregistrer un commentaire