InlineFormView: split off from TabularData template
This commit is contained in:
parent
913fb974c7
commit
2bf78b9f5d
100
templates/InlineFormView.php
Normal file
100
templates/InlineFormView.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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">';
|
||||
|
||||
if (!empty($form['fields']))
|
||||
{
|
||||
foreach ($form['fields'] as $name => $field)
|
||||
{
|
||||
if ($field['type'] === 'select')
|
||||
{
|
||||
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>';
|
||||
}
|
||||
else
|
||||
echo '
|
||||
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '" class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"', isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
||||
|
||||
if (isset($field['html_after']))
|
||||
echo $field['html_after'];
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
||||
|
||||
if (!empty($form['buttons']))
|
||||
foreach ($form['buttons'] as $name => $button)
|
||||
{
|
||||
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>';
|
||||
|
||||
if (isset($button['html_after']))
|
||||
echo $button['html_after'];
|
||||
}
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
</form>';
|
||||
else
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* TabularData.php
|
||||
* Contains the template that displays tabular data.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
||||
* Kabuki CMS (C) 2013-2025, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class TabularData extends SubTemplate
|
||||
@ -79,7 +79,7 @@ class TabularData extends SubTemplate
|
||||
|
||||
// Form controls?
|
||||
if (isset($form))
|
||||
$this->renderInlineForm($form);
|
||||
InlineFormView::renderInlineForm($form);
|
||||
|
||||
echo '
|
||||
</div>';
|
||||
@ -146,94 +146,4 @@ class TabularData extends SubTemplate
|
||||
echo '
|
||||
</tbody>';
|
||||
}
|
||||
|
||||
protected 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">';
|
||||
|
||||
if (!empty($form['fields']))
|
||||
{
|
||||
foreach ($form['fields'] as $name => $field)
|
||||
{
|
||||
if ($field['type'] === 'select')
|
||||
{
|
||||
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>';
|
||||
}
|
||||
else
|
||||
echo '
|
||||
<input name="', $name, '" id="field_', $name, '" type="', $field['type'], '" placeholder="', $field['placeholder'], '" class="form-control', isset($field['class']) ? ' ' . $field['class'] : '', '"', isset($field['value']) ? ' value="' . htmlspecialchars($field['value']) . '"' : '', '>';
|
||||
|
||||
if (isset($field['html_after']))
|
||||
echo $field['html_after'];
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
<input type="hidden" name="', Session::getSessionTokenKey(), '" value="', Session::getSessionToken(), '">';
|
||||
|
||||
if (!empty($form['buttons']))
|
||||
foreach ($form['buttons'] as $name => $button)
|
||||
{
|
||||
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>';
|
||||
|
||||
if (isset($button['html_after']))
|
||||
echo $button['html_after'];
|
||||
}
|
||||
|
||||
if (!empty($form['is_group']))
|
||||
echo '
|
||||
</div>';
|
||||
|
||||
if (!isset($form['is_embed']))
|
||||
echo '
|
||||
</form>';
|
||||
else
|
||||
echo '
|
||||
</div>';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user