Initial commit
commit
30f737ccb1
|
@ -0,0 +1,4 @@
|
|||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.drone.yml export-ignore
|
||||
test/ export-ignore
|
|
@ -0,0 +1,7 @@
|
|||
composer.lock
|
||||
composer.phar
|
||||
.idea/
|
||||
build/
|
||||
test/temp/
|
||||
vendor/
|
||||
test/.phpunit.result.cache
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013-2023 i15
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "fuzeworks/forms",
|
||||
"license": ["MIT"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Abel Hoogeveen",
|
||||
"email": "abel@i15.nl"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.1.0",
|
||||
"fuzeworks/core": "~1.3.0",
|
||||
"fuzeworks/mvcr": "~1.3.0",
|
||||
"fuzeworks/objectstorage": "~1.3.0",
|
||||
"fuzeworks/layout": "~1.3.0",
|
||||
"fuzeworks/webcomponent": "~1.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"fuzeworks/tracycomponent": "~1.3.0",
|
||||
"phpunit/phpunit": "^9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FuzeWorks\\Forms\\": "src/FuzeWorks/Forms/"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{varType FuzeWorks\Forms\Form $form}
|
||||
{varType FuzeWorks\Forms\Field $field}
|
||||
<form {$form->generateHtmlFormAttributes()|noescape}>
|
||||
{if $form->isValidated() && $form->isValid()}
|
||||
<div class="alert alert-success">
|
||||
<h5><i class="icon fas fa-check"></i> Alert!</h5>
|
||||
{$form->getName()} was successfully completed.
|
||||
</div>
|
||||
{else}
|
||||
<div n:foreach="$form->getFormErrors() as $error" class="alert alert-danger">
|
||||
<h5><i class="icon fas fa-check"></i> Error!</h5>
|
||||
{$error|noescape}
|
||||
</div>
|
||||
<div n:foreach="$form->getFormWarnings() as $warning" class="alert alert-warning">
|
||||
<h5><i class="icon fas fa-check"></i> Warning!</h5>
|
||||
{$warning|noescape}
|
||||
</div>
|
||||
{foreach $form->getFields() as $field}
|
||||
{switch get_class($field)}
|
||||
{case "FuzeWorks\Forms\Fields\HiddenField", "FuzeWorks\Forms\Fields\SubmitField", "FuzeWorks\Forms\Fields\ResetField", "FuzeWorks\Forms\Fields\DecoratorField"}
|
||||
{$field|noescape}
|
||||
{case "FuzeWorks\Forms\Fields\CheckboxField"}
|
||||
<div class="form-check">
|
||||
{$field->addClass("form-check-input")|noescape}
|
||||
<label for="{$field->getId()}" class="form-check-label">{$field->getLabel()}</label>
|
||||
{if $field->isValidated() && !$field->isValid()}
|
||||
<small class="text-danger">{$field->getErrors()|implode}</small>
|
||||
{/if}
|
||||
</div>
|
||||
{case "FuzeWorks\Forms\Fields\RadioField"}
|
||||
{$field|noescape}
|
||||
{default}
|
||||
<div class="form-group">
|
||||
<label for="{$field->getId()}">{$field->getLabel()}</label>
|
||||
{if $field->isValidated() && !$field->isValid()}
|
||||
{$field->class(["form-control", "is-invalid"])|noescape}
|
||||
<small class="text-danger">{$field->getErrors()|implode}</small>
|
||||
{elseif $field->isValidated() && $field->isValid()}
|
||||
{$field->class(["form-control", "is-valid"])|noescape}
|
||||
{else}
|
||||
{$field->addClass("form-control")|noescape}
|
||||
{/if}
|
||||
</div>
|
||||
{/switch}
|
||||
{/foreach}
|
||||
{/if}
|
||||
</form>
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Exceptions;
|
||||
use FuzeWorks\Exception\LibraryException;
|
||||
|
||||
class FormException extends LibraryException
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Exceptions;
|
||||
|
||||
class InputException extends FormException
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,393 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms;
|
||||
|
||||
abstract class Field
|
||||
{
|
||||
protected string $name;
|
||||
protected string $formName = '';
|
||||
protected ?string $identifier = null;
|
||||
protected ?string $label = null;
|
||||
protected ?string $note = null;
|
||||
protected mixed $value = null;
|
||||
protected array $errors;
|
||||
protected bool $lock = false;
|
||||
protected bool $optional = false;
|
||||
protected bool $validated = false;
|
||||
protected bool $valid = false;
|
||||
protected array $classNames = [];
|
||||
protected ?string $emptyErrorString = null;
|
||||
|
||||
/**
|
||||
* @var callable[]
|
||||
*/
|
||||
protected array $conditions = [];
|
||||
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates this field against its internal and added conditions.
|
||||
*
|
||||
* Returns true if all conditions are met, or false if there are errors.
|
||||
* If the result is false, a list of errors can be retrieved using the getErrors() method.
|
||||
* @see getErrors
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(): bool
|
||||
{
|
||||
// Prepare output variables
|
||||
$this->errors = [];
|
||||
$this->validated = true;
|
||||
$this->valid = true;
|
||||
|
||||
// Check if empty or null
|
||||
if (empty($this->value)) {
|
||||
// If the value is empty and not optional, turn it into an error
|
||||
if (!$this->optional) {
|
||||
$this->valid = false;
|
||||
if (!is_null($this->emptyErrorString))
|
||||
$this->errors[] = $this->emptyErrorString;
|
||||
else
|
||||
$this->errors[] = $this->getLabel() . " may not be empty.";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the value is empty but also optional, that's perfectly fine. Immediately accept without any further tests.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check validateField
|
||||
if (!$this->validateField())
|
||||
$this->valid = false;
|
||||
|
||||
// Check for conditions
|
||||
foreach ($this->conditions as $condition)
|
||||
if (!call_user_func($condition, $this))
|
||||
$this->valid = false;
|
||||
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the field has been validated.
|
||||
*
|
||||
* @see validate
|
||||
* @return bool
|
||||
*/
|
||||
public function isValidated(): bool
|
||||
{
|
||||
return $this->validated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the field has met all conditions during validation
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the valid status of the field to false, if so required by post-checks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invalidate(): void
|
||||
{
|
||||
$this->valid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the field, as was added with the construction of the field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently set value of the field.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue(): mixed
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique identifier of the field.
|
||||
*
|
||||
* If an identifier has been set, it shall return 'formName_fieldIdentifier'
|
||||
* If no identifier has been set, it shall return 'formName_fieldName'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
if (is_null($this->identifier))
|
||||
return $this->formName . "_" . $this->name;
|
||||
|
||||
return $this->formName . "_" . $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the label of this field, which is the most human-readable.
|
||||
*
|
||||
* If a label has been set, returns that label.
|
||||
* If no label has been set, returns ucfirst(fieldName).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return is_null($this->label) ? ucfirst($this->name) : $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the note of this field.
|
||||
*
|
||||
* Notes are there for the developer to categorize fields, if this is required.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNote(): ?string
|
||||
{
|
||||
return $this->note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of strings with all errors found during validation.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getErrors(): array
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current value of this field, which it may be validated against.
|
||||
* ALWAYS VERIFY AGAINST XSS ATTACKS!!!!!!!!!!
|
||||
*
|
||||
* If field is locked the value will not be updated.
|
||||
* @see lock
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setValue(mixed $value): static
|
||||
{
|
||||
if (!$this->lock)
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the identifier of the field.
|
||||
*
|
||||
* @param string $identifier
|
||||
* @return $this
|
||||
*/
|
||||
public function setId(string $identifier): static
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label of the field.
|
||||
*
|
||||
* @param string $label
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel(string $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the note of the field.
|
||||
*
|
||||
* @param string $note
|
||||
* @return $this
|
||||
*/
|
||||
public function setNote(string $note): static
|
||||
{
|
||||
$this->note = $note;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* When enabled, locks the field, so it may not be edited anymore.
|
||||
*
|
||||
* @param bool $lock
|
||||
* @return $this
|
||||
*/
|
||||
public function lock(bool $lock = true): static
|
||||
{
|
||||
$this->lock = $lock;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* When enabled, marks the field as optional, so that it may be left empty during validation.
|
||||
*
|
||||
* @param bool $opt
|
||||
* @return $this
|
||||
*/
|
||||
public function optional(bool $opt = true): static
|
||||
{
|
||||
$this->optional = $opt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a manual condition to the field that it will be validated against.
|
||||
*
|
||||
* @param callable $condition
|
||||
* @return $this
|
||||
*/
|
||||
public function condition(callable $condition): static
|
||||
{
|
||||
$this->conditions[] = $condition;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the string to be displayed when a value is not set and isn't optional.
|
||||
*
|
||||
* @param string $errorString
|
||||
* @return $this
|
||||
*/
|
||||
public function emptyErrorString(string $errorString): static
|
||||
{
|
||||
$this->emptyErrorString = $errorString;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error to be displayed on this field.
|
||||
*
|
||||
* @param string $errorString
|
||||
* @return $this
|
||||
*/
|
||||
public function addError(string $errorString): static
|
||||
{
|
||||
$this->errors[] = $errorString;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the CSS classnames to be printed inside the element.
|
||||
*
|
||||
* @param array $classNames
|
||||
* @return $this
|
||||
*/
|
||||
public function class(array $classNames): static
|
||||
{
|
||||
foreach ($classNames as $className)
|
||||
$this->classNames[] = $className;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one CSS classname to be printed inside the element
|
||||
*
|
||||
* @param string $class
|
||||
* @return $this
|
||||
*/
|
||||
public function addClass(string $class): static
|
||||
{
|
||||
$this->classNames[] = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CSS classnames to be printed inside the element
|
||||
*
|
||||
* @param array $classNames
|
||||
* @return $this
|
||||
*/
|
||||
public function setClasses(array $classNames): static
|
||||
{
|
||||
$this->classNames = $classNames;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function setFormName(string $formName): void
|
||||
{
|
||||
$this->formName = $formName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a validation test against internal conditions.
|
||||
*
|
||||
* Gets called by validate() method
|
||||
* @see validate
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected abstract function validateField(): bool;
|
||||
|
||||
/**
|
||||
* Generates a html string that will be added to the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function generateHtml(): string;
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->generateHtml();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
use FuzeWorks\Forms\Field;
|
||||
|
||||
class ButtonField extends Field
|
||||
{
|
||||
|
||||
protected string $type = "button";
|
||||
|
||||
/**
|
||||
* The submit button name
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected ?string $buttonText = null;
|
||||
protected array $classNames = ["btn", "btn-primary"];
|
||||
protected ?string $onClick = null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function validateField(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setButtonText(string $text): self
|
||||
{
|
||||
$this->buttonText = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function onClick(string $text): self
|
||||
{
|
||||
$this->onClick = $text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHtml(): string
|
||||
{
|
||||
$id = "id='".$this->getId()."'";
|
||||
$name = "name='".$this->getName()."'";
|
||||
$value = is_null($this->buttonText) ? "value='".ucfirst($this->getName())."'" : "value='".$this->buttonText."'";
|
||||
$class = "class='".implode(" ", $this->classNames)."'";
|
||||
$onClick = !is_null($this->onClick) ? "onclick='" . $this->onClick . "'" : "";
|
||||
|
||||
return "<input $class type='$this->type' $id $name $value $onClick>";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
use FuzeWorks\Forms\Field;
|
||||
|
||||
class CheckboxField extends Field
|
||||
{
|
||||
|
||||
// Marked as optional so that a different error message can be displayed
|
||||
protected bool $optional = true;
|
||||
protected mixed $value = false;
|
||||
|
||||
/**
|
||||
* Check the checkbox by default.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function checked(): static
|
||||
{
|
||||
$this->value = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setValue(mixed $value): static
|
||||
{
|
||||
if (!is_bool($value) && !is_null($value))
|
||||
$value = true;
|
||||
|
||||
return parent::setValue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require this field for validation.
|
||||
*
|
||||
* If an errorMessage is provided, it shall be displayed instead of the standard 'checkbox is required'.
|
||||
*
|
||||
* @param string|null $errorMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function required(string $errorMessage = null): static
|
||||
{
|
||||
$this->optional = false;
|
||||
if (!is_null($errorMessage))
|
||||
$this->emptyErrorString = $errorMessage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function validateField(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHtml(): string
|
||||
{
|
||||
$id = "id='".$this->getId()."'";
|
||||
$name = "name='".$this->getName()."'";
|
||||
$class = "class='".implode(" ", $this->classNames)."'";
|
||||
$value = $this->value ? "checked" : "";
|
||||
$lock = $this->lock ? "disabled" : "";
|
||||
|
||||
return "<input $class type='checkbox' $id $name $value $lock>";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class ColorField extends \FuzeWorks\Forms\Field
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function validateField(): bool
|
||||
{
|
||||
// TODO: Implement validateField() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHtml(): string
|
||||
{
|
||||
// TODO: Implement generateHtml() method.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class DateField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class DatetimeField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
use FuzeWorks\Forms\Field;
|
||||
|
||||
class DecoratorField extends Field
|
||||
{
|
||||
|
||||
protected string $content;
|
||||
|
||||
public function __construct(string $name, string $content)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->optional = true;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function validateField(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function generateHtml(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class EmailField extends TextField
|
||||
{
|
||||
|
||||
public function validateField(): bool
|
||||
{
|
||||
parent::validateField();
|
||||
|
||||
// Verify email validity
|
||||
if (!filter_var($this->value, FILTER_VALIDATE_EMAIL))
|
||||
{
|
||||
$this->valid = false;
|
||||
$this->errors[] = $this->getLabel() . " is not a valid email address.";
|
||||
}
|
||||
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
public function generateHtml(): string
|
||||
{
|
||||
$id = "id='".$this->getId()."'";
|
||||
$name = "name='".$this->getName()."'";
|
||||
$value = !is_null($this->value) ? "value='".$this->value."'" : "";
|
||||
$lock = $this->lock ? "disabled" : "";
|
||||
$placeholder = !is_null($this->placeholder) ? "placeholder='".$this->placeholder."'" : "";
|
||||
$maxLength = $this->maxLength > 0 ? "maxlength='".$this->maxLength."'" : "";
|
||||
$minLength = $this->minLength > 0 ? "minlength='".$this->minLength."'" : "";
|
||||
$class = "class='".implode(" ", $this->classNames)."'";
|
||||
|
||||
return "<input $class type='email' $id $name $value $lock $placeholder $maxLength $minLength>";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class FileField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
use FuzeWorks\Forms\Field;
|
||||
|
||||
class HiddenField extends Field
|
||||
{
|
||||
|
||||
protected bool $optional = true;
|
||||
|
||||
protected function validateField(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function generateHtml(): string
|
||||
{
|
||||
$id = "id='".$this->getId()."'";
|
||||
$name = "name='".$this->getName()."'";
|
||||
$value = !is_null($this->value) ? "value='".$this->value."'" : "";
|
||||
$class = "class='".implode(" ", $this->classNames)."'";
|
||||
|
||||
return "<input $class type='hidden' $id $name $value>";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class ImageField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class MonthField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class NumberField
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
|
||||
class PasswordField extends TextField
|
||||
{
|
||||
public function generateHtml(): string
|
||||
{
|
||||
$id = "id='".$this->getId()."'";
|
||||
$name = "name='".$this->getName()."'";
|
||||
$placeholder = !is_null($this->placeholder) ? "placeholder='".$this->placeholder."'" : "";
|
||||
$maxLength = $this->maxLength > 0 ? "maxlength='".$this->maxLength."'" : "";
|
||||
$minLength = $this->minLength > 0 ? "minlength='".$this->minLength."'" : "";
|
||||
$class = "class='".implode(" ", $this->classNames)."'";
|
||||
|
||||
return "<input $class type='password' $id $name $placeholder $maxLength $minLength>";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Forms Library
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-${YEAR} i15
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author i15
|
||||
* @copyright Copyright (c) 2013 - ${YEAR}, i15. (http://i15.nl)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link https://i15.nl
|
||||
* @since Version 1.3.0
|
||||
*
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Forms\Fields;
|
||||
use FuzeWorks\Forms\Exceptions\InputException;
|
||||
use FuzeWorks\Forms\Field;
|
||||
|
||||
class RadioField extends Field
|
||||
{
|
||||
|
||||
protected array $options = [];
|
||||
protected array $classNames = ['form-group'];
|
||||
|
||||
/**
|
||||
* Add an option to the RadioField
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|null $label
|
||||
* @return $this
|
||||
* @throws InputException
|
||||
*/
|
||||
public function addOption(string $value, string $label = null): self
|
||||
{
|
||||
if (isset($this->options[$value]))
|
||||
throw new InputException("Could not add value to field. Value already exists.");
|
||||
|
||||
// Add to the values
|
||||
if (is_null($label))
|
||||
$this->options[$value] = $value;
|
||||
else
|
||||
$this->options[$value] = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk add options to the RadioField
|
||||