Minor fix with submit buttons

This commit is contained in:
Jose Gonzalez 2023-02-14 12:16:09 +01:00
parent 1d682521e9
commit e499e13753
1 changed files with 24 additions and 21 deletions

View File

@ -3409,26 +3409,23 @@ function html_print_action_buttons(string $content, array $parameters=[], bool $
function html_print_submit_button($label='OK', $name='', $disabled=false, $attributes='', $return=false) function html_print_submit_button($label='OK', $name='', $disabled=false, $attributes='', $return=false)
{ {
if (is_string($attributes) === true) { if (is_string($attributes) === true) {
$attributes = []; // Convert Attributes in array for handle in the principal function.
$tmp = [];
$tmp['rawAttributes'] = $attributes;
$attributes = $tmp;
} }
// Set the button type from here. // Set the button type from here.
$attributes['type'] = 'submit'; $attributes['type'] = 'submit';
$output = html_print_button( return html_print_button(
$label, $label,
$name, $name,
$disabled, $disabled,
(isset($attributes['onclick']) === true) ? $attributes['onclick'] : '', (isset($attributes['onclick']) === true) ? $attributes['onclick'] : '',
$attributes, $attributes,
true $return
); );
if ($return === false) {
echo $output;
} else {
return $output;
}
} }
@ -3480,14 +3477,16 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $
$classes .= ' '.$value; $classes .= ' '.$value;
} else if ($attribute === 'fixed_id') { } else if ($attribute === 'fixed_id') {
$fixedId = $value; $fixedId = $value;
} else if ($attribute === 'rawAttributes') {
$buttonType = ($attr_array['type'] ?? 'button');
$buttonAttributes = $value;
break;
} else { } else {
$attributes .= $attribute.'="'.$value.'" '; $attributes .= $attribute.'="'.$value.'" ';
} }
} }
} else if (empty($attributes) === false && is_string($attributes) === true) { } else if (empty($attributes) === false && is_string($attributes) === true) {
$tmpData = explode(' ', $attributes); $buttonAttrutes = explode(' ', $attributes);
$iconToUse = $tmpData[(array_search('sub', $tmpData) + 1)];
$iconToUse = preg_replace('([^A-Za-z])', '', $iconToUse);
} }
if (empty($iconToUse) === false || (isset($buttonMode) === true && $buttonMode !== 'onlyIcon')) { if (empty($iconToUse) === false || (isset($buttonMode) === true && $buttonMode !== 'onlyIcon')) {
@ -3523,19 +3522,23 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $
$classes .= ' disabled_action_button'; $classes .= ' disabled_action_button';
} }
$parameters = []; if (empty($buttonAttributes) === true) {
$parameters[] = 'class="'.$classes.'"'; $parameters = [];
$parameters[] = (empty($name) === false) ? ' name="'.$name.'"' : ''; $parameters[] = 'class="'.$classes.'"';
$parameters[] = 'id="'.((empty($fixedId) === false) ? $fixedId : 'button-'.$name ).'"'; $parameters[] = (empty($name) === false) ? ' name="'.$name.'"' : '';
$parameters[] = (empty($label) === false) ? ' value="'.$label.'"' : ''; $parameters[] = 'id="'.((empty($fixedId) === false) ? $fixedId : 'button-'.$name ).'"';
$parameters[] = (empty($script) === false) ? ' onClick="'.$script.'"' : ''; $parameters[] = (empty($label) === false) ? ' value="'.$label.'"' : '';
$parameters[] = ($disabled === true) ? ' disabled' : ''; $parameters[] = (empty($script) === false) ? ' onClick="'.$script.'"' : '';
$parameters[] = (empty($attributes) === false) ? $attributes : ''; $parameters[] = ($disabled === true) ? ' disabled' : '';
$parameters[] = (empty($attributes) === false) ? $attributes : '';
$buttonAttributes = implode(' ', $parameters);
}
$output = sprintf( $output = sprintf(
'<button type="%s" %s>%s</button>', '<button type="%s" %s>%s</button>',
$buttonType, $buttonType,
implode(' ', $parameters), $buttonAttributes,
$content $content
); );