I have a table called persons with id and name fields.
I have a create.php view that loads the model called Persons and now I want to add a checkbox called hasCar to show if a person has a car (so it is a boolean condition).
Then I have the send button that send the $model array of the form to the controller so I need to add the hasCar variable to $model array.
But the checkbox is not a column of the persons table so I got some errors because it is not part of the model.
I added the checkbox in this way but it is not working, of course.
<?= $form->field($model, 'hasCar')->checkbox(); ?>
Is it possible to send the hasCar variable inside the $model array? I mean, how can I send the hasCar variable to the controller when the send button is pressed?
Create a new model extending Person that contains hasCar member, and load the model from PersonForm class, such as:
You can't pass the variable to the $model object orbit is affiliated with a db table, you are right about this. You need to pass the variable to the controller via a request method (GET, POST).
Try :
for POST, and :
for GET.
Also on the form add the checkbox as an HTML class component.
EXAMPLE:
CONTROLLER:
VIEW:
More on ActiveFormJS: enter link description here
I hope this answer covered you.
Damian