106 lines
2.7 KiB
PHP
106 lines
2.7 KiB
PHP
<?php
|
|
/*****************************************************************************
|
|
* InlineFormView.php
|
|
* Contains the template that renders inline forms.
|
|
*
|
|
* Kabuki CMS (C) 2013-2025, Aaron van Geffen
|
|
*****************************************************************************/
|
|
|
|
class InlineFormView
|
|
{
|
|
public static function renderInlineForm($form)
|
|
{
|
|
if (!isset($form['is_embed']))
|
|
echo '
|
|
<form action="', $form['action'], '" method="', $form['method'], '" class="', $form['class'], '">';
|
|
else
|
|
echo '
|
|
<div class="', $form['class'], '">';
|
|
|
|
if (!empty($form['is_group']))
|
|
echo '
|
|
<div class="input-group">';
|
|
|
|
foreach ($form['controls'] as $name => $control)
|
|
{
|
|
if ($control['type'] === 'select')
|
|
self::renderSelectBox($control, $name);
|
|
elseif ($control['type'] === 'submit')
|
|
self::renderSubmitButton($control, $name);
|
|
else
|
|
self::renderInputBox($control, $name);
|
|
}
|
|
|
|
echo '
|
|
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
|
|
|
if (!empty($form['is_group']))
|
|
echo '
|
|
</div>';
|
|
|
|
if (!isset($form['is_embed']))
|
|
echo '
|
|
</form>';
|
|
else
|
|
echo '
|
|
</div>';
|
|
}
|
|
|
|
private static function renderInputBox(array $field, $name)
|
|
{
|
|
echo '
|
|
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" ',
|
|
'class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"',
|
|
isset($field['placeholder']) ? ' placeholder="' . $field['placeholder'] . '"' : '',
|
|
isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
|
}
|
|
|
|
private static function renderSelectBox(array $field, $name)
|
|
{
|
|
echo '
|
|
<select class="form-select" name="', $name, '"',
|
|
(isset($field['onchange']) ? ' onchange="' . $field['onchange'] . '"' : ''), '>';
|
|
|
|
foreach ($field['values'] as $value => $caption)
|
|
{
|
|
if (!is_array($caption))
|
|
{
|
|
echo '
|
|
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
|
}
|
|
else
|
|
{
|
|
$label = $value;
|
|
$options = $caption;
|
|
|
|
echo '
|
|
<optgroup label="', $label, '">';
|
|
|
|
foreach ($options as $value => $caption)
|
|
{
|
|
echo '
|
|
<option value="', $value, '"', $value === $field['selected'] ? ' selected' : '', '>', $caption, '</option>';
|
|
}
|
|
|
|
echo '
|
|
</optgroup>';
|
|
}
|
|
}
|
|
|
|
echo '
|
|
</select>';
|
|
}
|
|
|
|
private static function renderSubmitButton(array $button, $name)
|
|
{
|
|
echo '
|
|
<button class="btn ', isset($button['class']) ? $button['class'] : 'btn-primary', '" ',
|
|
'type="', $button['type'], '" name="', $name, '"';
|
|
|
|
if (isset($button['onclick']))
|
|
echo ' onclick="', $button['onclick'], '"';
|
|
|
|
echo '>', $button['caption'], '</button>';
|
|
}
|
|
}
|