dropdownlist validation

got a dropdownlist with 3 options namely 0,1,2. why wont this work to validate. [[‘marital_status’, ‘type’] ‘in’, ‘range’=>‘0’,‘1’,‘2’]. can the db field be of type ‘tinynt’

you can also do


range=>range(0,2)

so you don’t have to type all of them.

Your going to have to post more than you did to get an answer

Post:

dropdown list (function populating data if applicable)

Model rules for above field

Are you using scenarios? If so post them for the scenario that isn’t validating

the error generated is ‘marital status is invalid’. the database field is tinyint .

kindly share ur dropdown code here

u r passing name in place of id.(may be)

_form.php

<?php

use yii\helpers\Html;

use yii\widgets\ActiveForm;

use yii\jui\DatePicker;

/* @var $this yii\web\View */

/* @var $model app\models\Registration */

/* @var $form yii\widgets\ActiveForm */

?>

<div class="registration-form">

&lt;?php &#036;form = ActiveForm::begin(); ?&gt;





&lt;?php echo &#036;form-&gt;field(&#036;model, 'gender[]')-&gt;dropDownList(['0' =&gt; 'N/A', '1' =&gt; 'Male', '2' =&gt; 'Female']) ?&gt;





&lt;?php echo &#036;form-&gt;field(&#036;model, 'marital_status[]')-&gt;dropDownList(['0' =&gt; 'N/A', '1' =&gt; 'Married', '2' =&gt; 'Single']) ?&gt;


&lt;?php echo &#036;form-&gt;field(&#036;model, 'type[]')-&gt;dropDownList(['1' =&gt; 'Farmer', '2' =&gt; 'Semen Supplier']) ?&gt;





&lt;div class=&quot;form-group&quot;&gt;


    &lt;?= Html::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; &#036;model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;


&lt;/div&gt;





&lt;?php ActiveForm::end(); ?&gt;

</div>

=========================================================================

Registration.php

<?php

namespace app\models;

use Yii;

/**

  • This is the model class for table "registration".

  • @property string $gender

  • @property string $marital_status

  • @property string $type

  • @property string $user_id

*/

class Registration extends \yii\db\ActiveRecord

{

/**


 * @inheritdoc


 */


public static function tableName()


{


    return 'registration';


}





/**


 * @inheritdoc


 */


public function rules()


{


    return [


		[['gender' , 'marital_status', 'type'], 'in', 'range' =&gt; ['0', '1', '2']]


    ];


}





/**


 * @inheritdoc


 */


public function attributeLabels()


{


    return [


        'gender' =&gt; 'Gender',


        'marital_status' =&gt; 'Marital Status',


        'type' =&gt; 'Type',


    ];


}

}