Обновить src/Form.php

This commit is contained in:
parent 1f5370b743
commit e87a54a874

View File

@ -2,6 +2,14 @@
namespace src;
use src\inputs\Checkbox;
use src\inputs\Select;
use src\inputs\TextInput;
use src\inputs\Label;
use src\inputs\Radio;
use src\inputs\TextArea;
use src\inputs\Button;
class Form {
/**
@ -14,30 +22,14 @@ class Form {
}
/**
* Генерация текстового инпута
*
* @param string $name
* @param array $paramsArray
* @return void
*/
public function input(string $name, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<input name='$name' $paramsString >";
}
/**
* @param array $data
* @return string
*/
public function createParams(array $data = []): string
public function textInput(string $name, array $paramsArray = []): void
{
$paramsString = "";
foreach($data as $key => $param){
$paramsString .= $key . "='" . $param . "'";
}
return $paramsString;
TextInput::build($name, $paramsArray);
}
/**
@ -46,10 +38,9 @@ class Form {
* @param array $paramsArray
* @return void
*/
public function createCheckbox(string $name, string $value, array $paramsArray = []): void
public function checkBox(string $name, string $value, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<input name='$name' type='checkbox' value='$value' $paramsString >";
Checkbox::build($name, $value, $paramsArray);
}
@ -58,10 +49,9 @@ class Form {
* @param array $paramsArray
* @return void
*/
public function createLabel(string $title, array $paramsArray = []): void
public function label(string $title, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<label $paramsString >$title</label>";
Label::build($title, $paramsArray);
}
/**
@ -69,10 +59,9 @@ class Form {
* @param array $paramsArray
* @return void
*/
public function createRadio(string $name, array $paramsArray = []): void
public function radio(string $name, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<input name='$name' type='radio' $paramsString>";
Radio::build($name, $paramsArray);
}
/**
@ -81,19 +70,22 @@ class Form {
* @param array $paramsArray
* @return void
*/
public function createTextarea(string $name, string $value = "", array $paramsArray = []): void
public function textarea(string $name, string $value = "", array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<textarea name='$name' $paramsString>$value</textarea>";
TextArea::build($name, $value, $paramsArray);
}
/**
* @param string $name
* @param array $options
* @param $value
* @param array $paramsArray
* @return void
*/
public function createBeginSelect(string $name, array $paramsArray = []): void
public function select(string $name, array $options = [], $value = null, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<select name='$name' $paramsString>";
Select::build($name, $options, $value, $paramsArray);
}
/**
@ -102,30 +94,9 @@ class Form {
* @param array $paramsArray
* @return void
*/
public function createOption(string $name, string $value, array $paramsArray = []): void
public function button(string $name, string $value, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<option name='$name' $paramsString'>$value</option>";
}
/**
* @return void
*/
public function createEndSelect(): void
{
echo "</select>";
}
/**
* @param string $name
* @param string $value
* @param array $paramsArray
* @return void
*/
public function createButton(string $name, string $value, array $paramsArray = []): void
{
$paramsString = $this->createParams($paramsArray);
echo "<button name='$name' $paramsString>$value</button>";
Button::build($name, $value, $paramsArray);
}
/**