This commit is contained in:
Kavalar 2024-12-09 23:06:48 +03:00
commit 53e5fadfc1
2 changed files with 13 additions and 5 deletions

View File

@ -31,9 +31,9 @@ class ActiveForm
* @param string $action
* @return void
*/
public function beginForm(string $action): void
public function beginForm(string $action, string $enctype = 'application/x-www-form-urlencoded'): void
{
echo "<form method='POST' action='$action'>";
echo "<form method='POST' action='$action' enctype='$enctype'>";
}
/**

View File

@ -12,10 +12,18 @@ trait CreateOption
public function createOption(array $options, $value = null): string
{
$optionsString = "";
foreach ($options as $val => $title){
$selected = (int)$value === $val ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
if (is_array($value)) {
foreach ($options as $val => $title) {
$selected = in_array($title, $value) ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
} else {
foreach ($options as $val => $title) {
$selected = (int)$value === $val ? "selected" : "";
$optionsString .= "<option $selected value='$val'>$title</option>";
}
}
return $optionsString;
}
}