Save checkbox values in plugins
Posted: Sun Jan 06, 2019 4:05 pm
Hello!
In the plugin settings, whenever I add input type="text", I can save any values in an array just fine. I save the settings and the values stay there.
But checkboxes always reset because I can't seem to save checkbox values in arrays like text values.
Here's the array where I save the values for input fields.
And here's the input in the plugins settings. The 'cars' input saves, but I struggle with saving 'bikes' value. (probably because I never even stated the value for the checkbox)
As it turned out, there are no examples of checkboxes anywhere in Bludit , and I couldn't find any plugins that would have them, so I've been struggling with it myself. What's the best way to make checkboxes work?
Thank you!
In the plugin settings, whenever I add input type="text", I can save any values in an array just fine. I save the settings and the values stay there.
But checkboxes always reset because I can't seem to save checkbox values in arrays like text values.
Here's the array where I save the values for input fields.
Code: Select all
public function init() {
$this->dbFields = array(
'cars' => '', //text
'bikes' => '' //checkbox
);
}
Code: Select all
// Cars - text
$html .= '<div>';
$html .= '<input name="cars" type="text" class="form-control" value="'.$this->getValue('cars').'">';
$html .= '</div>'.PHP_EOL;
// Bikes - checkbox
$html .= '<div>';
$html .= '<input name="bikes" type="text" class="form-control" value="'.$this->getValue('bikes').'">';
$html .= '</div>'.PHP_EOL;
Thank you!