Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active February 13, 2020 13:39
Show Gist options
  • Save ashour/b5a34299768ef982e068a75471301190 to your computer and use it in GitHub Desktop.
Save ashour/b5a34299768ef982e068a75471301190 to your computer and use it in GitHub Desktop.
<?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