How to create checkbox field with dummy attribute?

I’m working on a basic user profile page where users can upload a photo. What I’d like to do is add a checkbox to the page that, if checked, deletes their photo. In reality, it would just empties the “photo_location” for their instance in the table (photo would still be saved elsewhere, just no longer displayed).

I don’t want to create a “delete” column in the table, but I can’t figure out how to generate the checkbox using ActiveField without a corresponding attribute.

Further, within the controller, how would I determine if the box is checked? Obviously, the app needs to know so that it can empty the "photo_location" information in the table.

You do not need an ActiveField. Just use Html::checkbox(‘delete_photo’).

In your controller you can do:




if ($_POST['delete_photo']) {

    $model->photo_location = '';

}



Thanks, that was easy enough!