Search field is also showing required

Hi,

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 :)

If you are using the default Yii setup you should have a model and a model that extends the base model. For example you should have YourModel then a YourModelSearch. Check the rules in the YourModelSearch model.