v1.0 Initial commit of project
This commit is contained in:
90
pub/bin/php/Classes/formBuilder.php
Normal file
90
pub/bin/php/Classes/formBuilder.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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 ?> <?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 ?> <?php echo $this->submitButtonText ?></button>
|
||||
<?php }
|
||||
|
||||
foreach ($this->extraButtonsArray as $numb => $extraButtonArray) { ?>
|
||||
<a href="<?php echo $extraButtonArray['buttonHref'] ?>" class="btn btn-<?php echo $extraButtonArray['buttonColor'] ?>"><?php echo $extraButtonArray['buttonIcon'] ?> <?php echo $extraButtonArray['buttonText'] ?></a>
|
||||
<?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 }
|
||||
}
|
||||
Reference in New Issue
Block a user