Last active
February 13, 2020 13:39
-
-
Save ashour/b5a34299768ef982e068a75471301190 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'FormControl.php'; | |
require_once dirname(__FILE__) . '/../functions.php'; | |
class Checkbox extends FormControl | |
{ | |
public function __construct($name, $errors) | |
{ | |
parent::__construct($name, $errors, 'checkbox'); | |
} | |
public function render() | |
{ | |
$name = $this->name; | |
$label = __($this->name); | |
$inputClasses = $this->inputClasses('checkbox'); | |
$checkedAttr = isset($_REQUEST[$this->name]) ? 'checked' : ''; | |
$errorClasses = $this->errorClasses(); | |
$errorText = $this->errors[$this->name] ?? null; | |
return <<<HTML | |
<div class="field"> | |
<div class="control"> | |
<label class="{$inputClasses}"> | |
<input type="checkbox" name="{$name}" {$checkedAttr}> | |
{$label} | |
</label> | |
<p class="{$errorClasses}">{$errorText}</p> | |
</div> | |
</div> | |
HTML; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment