src/Yggdrasil/Utils/Templating/FormExtension.php
public function addFormField(string $name): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $input = HtmlTag::createElement('input')
            ->set('type', $options['input']['type'] ?? 'text')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $input->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'input'   => $input,
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        if (in_array($options['input']['type'] ?? 'text', ['checkbox', 'radio', 'file'])) {
            $wrapper->addElement($input);
            $wrapper->addElement($label);
        } else {
            $wrapper->addElement($label);
            $wrapper->addElement($input);
        }

        $wrapper->addElement($caption);

        echo $wrapper;
    }
public function addFormField(string $name): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $input = HtmlTag::createElement('input')
            ->set('type', $options['input']['type'] ?? 'text')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $input->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'input'   => $input,
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        if (in_array($options['input']['type'] ?? 'text', ['checkbox', 'radio', 'file'])) {
            $wrapper->addElement($input);
            $wrapper->addElement($label);
        } else {
            $wrapper->addElement($label);
            $wrapper->addElement($input);
        }

        $wrapper->addElement($caption);

        echo $wrapper;
    }
public function addFormField ( string $ name ) : void { $ options = $ this -> formOptions [ 'fields' ] [ $ name ] ; $ wrapper = $ this -> createWrapper ( ) ; $ label = '' ; if ( isset ( $ options [ 'label' ] [ 'text' ] ) ) { $ label = $ this -> createLabel ( $ options [ 'label' ] [ 'text' ] , $ name ) ; unset ( $ options [ 'label' ] [ 'text' ] ) ; } $ input = HtmlTag :: createElement ( 'input' ) -> set ( 'type' , $ options [ 'input' ] [ 'type' ] ?? 'text' ) -> set ( 'id' , $ name ) -> set ( 'name' , $ name ) ; $ caption = '' ; if ( isset ( $ options [ 'caption' ] [ 'text' ] ) ) { $ input -> set ( 'aria-describedby' , $ name . '_caption' ) ; $ caption = $ this -> createCaption ( $ options [ 'caption' ] [ 'text' ] , $ name ) ; unset ( $ options [ 'caption' ] [ 'text' ] ) ; } $ elements = [ 'wrapper' => $ wrapper , 'label' => $ label , 'input' => $ input , 'caption' => $ caption ] ; foreach ( $ elements as $ name => $ element ) { $ $ name = $ this -> assignOptionsToElement ( $ options , $ name , $ element ) ; } if ( in_array ( $ options [ 'input' ] [ 'type' ] ?? 'text' , [ 'checkbox' , 'radio' , 'file' ] ) ) { $ wrapper -> addElement ( $ input ) ; $ wrapper -> addElement ( $ label ) ; } else { $ wrapper -> addElement ( $ label ) ; $ wrapper -> addElement ( $ input ) ; } $ wrapper -> addElement ( $ caption ) ; echo $ wrapper ; }
Adds field to HTML form

@param string $name Form field name, equivalent to ID and name attributes
Adds field to HTML form