Search field is also showing required


I am newbee to yii2 and I’m using yii2 advanced framework I have made a custom search form for a page and the form includes the field that is required while creating or updating(rule added in model as required) and another field that is normal field(not a require field on creation/insert).

When I click on search button it’s showing feild1 is required.I need by search form in such a way that I can filter with field1 or field2.

I may be wrong somewhere please advice me on the above concern.

Here is my model class rule function

public function rules()


    return [

        [['field1'], 'required'],

        [['inserted_date', 'updated_date', 'is_deleted','is_active'], 'integer'],

        [['field1'], 'string', 'max' => 255],

        [['field2', 'field3', 'field4', 'field5'], 'string', 'max' => 50],



Thanks In advance :)

Please check your rules in Search Model. You may be given like

[['field1'], 'required'], or [['field1', 'field2'], 'required'].

If so remove the attributes from required condition and add those attributes it into safe or integer or as needed condition.

Thanks for the reply

Whether I need to create a seperate model for search can’t I achieve with the existing model?

Yes you can , but it’s advised to use search model as separately in Yii.