Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
46564f9450 | |||
dc7e2c80a4 | |||
53e5fadfc1 | |||
9dfb6a52c3 | |||
45e57367d3 | |||
ddb17cc473 |
@ -31,9 +31,9 @@ class ActiveForm
|
|||||||
* @param string $action
|
* @param string $action
|
||||||
* @return void
|
* @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'>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
16
src/builders/EmailBuilder.php
Executable file
16
src/builders/EmailBuilder.php
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace itguild\forms\builders;
|
||||||
|
|
||||||
|
|
||||||
|
use itguild\forms\inputs\BaseInput;
|
||||||
|
use itguild\forms\inputs\EmailInput;
|
||||||
|
use itguild\forms\inputs\TextInput;
|
||||||
|
|
||||||
|
class EmailBuilder implements Builder
|
||||||
|
{
|
||||||
|
public static function build(string $name, array $params = []): BaseInput
|
||||||
|
{
|
||||||
|
return new EmailInput(name: $name, paramsArray: $params);
|
||||||
|
}
|
||||||
|
}
|
62
src/inputs/EmailInput.php
Executable file
62
src/inputs/EmailInput.php
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace itguild\forms\inputs;
|
||||||
|
|
||||||
|
use itguild\forms\debug\Debug;
|
||||||
|
use itguild\forms\inputs\BaseInput;
|
||||||
|
use itguild\forms\templates\bootstrap5\Bootstrap5Template;
|
||||||
|
use itguild\forms\templates\Simple\SimpleTemplate;
|
||||||
|
use itguild\forms\templates\Template;
|
||||||
|
use itguild\forms\traits\CreateParams;
|
||||||
|
|
||||||
|
class EmailInput extends BaseInput
|
||||||
|
{
|
||||||
|
|
||||||
|
use CreateParams;
|
||||||
|
private string $name;
|
||||||
|
private array $paramsArray;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param array $paramsArray
|
||||||
|
*/
|
||||||
|
public function __construct(string $name, array $paramsArray = [])
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
$this->paramsArray = $paramsArray;
|
||||||
|
$this->inputTemplate = new SimpleTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function create(): self
|
||||||
|
{
|
||||||
|
$paramsString = $this->createParams($this->paramsArray);
|
||||||
|
$label = "";
|
||||||
|
$input = "<input name='$this->name' type='email' $paramsString >";
|
||||||
|
|
||||||
|
$this->createLabel();
|
||||||
|
|
||||||
|
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
|
||||||
|
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param array $paramsArray
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function build(string $name, array $paramsArray = []): void
|
||||||
|
{
|
||||||
|
$input = new self($name, $paramsArray);
|
||||||
|
$input->create()->render();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,10 +12,18 @@ trait CreateOption
|
|||||||
public function createOption(array $options, $value = null): string
|
public function createOption(array $options, $value = null): string
|
||||||
{
|
{
|
||||||
$optionsString = "";
|
$optionsString = "";
|
||||||
|
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) {
|
foreach ($options as $val => $title) {
|
||||||
$selected = (int)$value === $val ? "selected" : "";
|
$selected = (int)$value === $val ? "selected" : "";
|
||||||
$optionsString .= "<option $selected value='$val'>$title</option>";
|
$optionsString .= "<option $selected value='$val'>$title</option>";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $optionsString;
|
return $optionsString;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ trait CreateParams
|
|||||||
{
|
{
|
||||||
$paramsString = "";
|
$paramsString = "";
|
||||||
foreach($data as $key => $param){
|
foreach($data as $key => $param){
|
||||||
if(is_string($param)){
|
if(is_string($param) || is_numeric($param)){
|
||||||
$paramsString .= $key . "='" . $param . "'";
|
$paramsString .= $key . "='" . $param . "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user