Files
Sentri/pub/bin/php/Classes/formBuilder.php
2026-01-01 10:54:18 +01:00

90 lines
3.2 KiB
PHP

<?php
namespace bin\php\Classes;
class formBuilder
{
public $title;
public $icon;
public $submitButton;
public $closeButton;
public $closeButtonLocation;
public $submitButtonColor;
public $submitButtonText;
public $submitButtonIcon;
private $extraButtonsArray = array();
public function __construct($title, $icon, $closeButtonLocation, $submitButton = true, $closeButton = true)
{
$this->title = __($title);
$this->icon = $icon;
$this->submitButton = $submitButton;
$this->closeButton = $closeButton;
$this->closeButtonLocation = $closeButtonLocation;
$this->submitButtonColor = 'primary';
$this->submitButtonText = __($title);
$this->submitButtonIcon = $icon;
}
public function startForm()
{ ?>
<div class="row"><div class="col-md-8 ms-auto me-auto"><div class="card">
<div class="card-header">
<h3><?php echo $this->icon ?>&nbsp; &nbsp;&nbsp;<?php echo $this->title ?></h3>
</div>
<?php }
public function endForm()
{ ?>
</div></div></div>
<?php }
# Add extra buttons to the form footer between the submit and close button
# Array example:
# array(
# 0 => array(
# 'buttonText' => 'testButton2123',
# 'buttonIcon' => 'ico123123ncontnet',
# 'buttonHref' => 'test'
# 'buttonColor' => 'success'
# ) > next array
public function addExtraButtons($extraButtonsArray)
{
foreach ($extraButtonsArray as $numb => $extraButtonArray) {
if (is_array($extraButtonArray)) {
if (array_key_exists('buttonIcon', $extraButtonArray) && array_key_exists('buttonText', $extraButtonArray) && array_key_exists('buttonHref', $extraButtonArray) && array_key_exists('buttonColor', $extraButtonArray)) {
array_push($this->extraButtonsArray, $extraButtonArray);
return true;
}
}
}
return false;
}
public function formFooter()
{ ?>
<div class="card-footer pt-3">
<div class="row">
<div class="col d-flex justify-content-end">
<?php if ($this->submitButton) { ?>
<button type="submit" class="btn btn-<?php echo $this->submitButtonColor ?>"><?php echo $this->submitButtonIcon ?>&nbsp;<?php echo $this->submitButtonText ?></button>&nbsp; &nbsp;
<?php }
foreach ($this->extraButtonsArray as $numb => $extraButtonArray) { ?>
<a href="<?php echo $extraButtonArray['buttonHref'] ?>" class="btn btn-<?php echo $extraButtonArray['buttonColor'] ?>"><?php echo $extraButtonArray['buttonIcon'] ?>&nbsp;<?php echo $extraButtonArray['buttonText'] ?></a>&nbsp; &nbsp;
<?php }
if ($this->closeButton) { ?>
<a href="<?php echo $this->closeButtonLocation ?>" class="btn btn-danger">
<i class="fas fa-times"></i> <?php echo __('close') ?>
</a>
<?php } ?>
</div>
</div>
</div>
<?php }
}