Case Study: Handling MySQL Growth With a PHP Class - Formmode (Page 4 of 5 )
What is the class variable called $formmode? Well, let's say that you want the field published to be a checkbox in your form. The tricky part is to check if the field is check or not checked, especially with the save() function we use in this object.
To solve this, I added another method to WSDynamicObject called addFormModeField;
Although the naming of the function could have been better, the functionality works, and the method is used like this from the WSDocument class:
// Form Mode Behaviour $this->addFormModeField("published","checkbox");
This simply says that the field published should be treated as a checkbox, so when we add a form to create or update an instance of WSDocument, we call the method:
The function formMode() runs through the array formmode, and set the value to checked if the value is 1 and sets it blank if the value is 0. When the object is saved, the reversed action makes sure that checked = 1 in your MySQL table.