phpmysqlcodeignitercrudgrocery-crud

Setting a default value of control in Grocery CRUD + Code Igniter


I need to set a default value of the field in Grocery CRUD.

Basically, the respective data column IsActive is set to NOT NULL.

I need to see that while adding the record, IsActive should be set to true or false but not NULL by default.

I looked for a reference all over the Internet but did not got the perfect solution for that.

Current view (in add mode)

enter image description here

So in case I do not set the rules to required, the form will post a NULL to the database.

While I need something like this (by default). enter image description here

So that the user is not required to add a value (it is not mandatory to set the field to true of false)


Solution

  • You can set default rules for a column at the database level irrespective of any framework/library. Use DEFAULT keyword.

       IsActive ENUM('active','inactive') NOT NULL DEFAULT 'active'