{define input, $name, $value, $type = 'text', $class, $id, $disabled, $size, $minlength, $maxlength, $pattern, $placeholder, $readonly, $required, $autofocus, $autocomplete, $list, $checked, $min, $max, $step}
{var $id = $id ?? str_replace( array( '[', ']'), array( '_', '' ), $name )}
{if 'checkbox' == $type}
<input type="hidden" name="{$name}" value="0">
{/if}
<input type="{$type}" id="{$id}" name="{$name}" n:attr="class: $class, value: $value, disabled: $disabled, size: $size, minlength: $minlength, maxlength: $maxlength, pattern: $pattern, placeholder: $placeholder, readonly: $readonly, required: $required, autofocus: $autofocus, autocomplete: $autocomplete, list: $list, checked: (bool)$checked, min: $min, max: $max, step: $step">
{/define}

{define select, $name, $value, $options, $class, $disabled, $size, $required, $autofocus, $multiple, $prompt}
{var $id = str_replace( array( '[', ']'), array( '_', '' ), $name )}
<select name="{$name}" id="{$id}" n:attr="class: $class, disabled: $disabled, size: $size, required: $required, autofocus: $autofocus, multiple: $multiple">
  {ifset $prompt}<option value="">{if true !== $prompt}{$prompt}{/if}</option>{/ifset}
  {foreach $options as $key => $label}
  <option value="{$key}"{if ( (is_array( $value ) && in_array( $key, $value ) ) || ( $key == $value ) )} selected{/if}>{$label}</option>
  {/foreach}
</select>
{/define}

{define textarea, $name, $value, $class, $rows, $cols, $disabled, $maxlength, $placeholder, $readonly, $required, $autofocus, $autocomplete}
{var $id = str_replace( array( '[', ']'), array( '_', '' ), $name )}
<textarea id="{$id}" name="{$name}" n:attr="class: $class, rows: $rows, cols: $cols, disabled: $disabled, maxlength: $maxlength, placeholder: $placeholder, readonly: $readonly, required: $required, autofocus: $autofocus, autocomplete: $autocomplete">{ifset $value}{$value}{/ifset}</textarea>
{/define}
