src/template/Html.php
public static function beginForm($action = null, $method = 'post', $name = null, $options = [])
    {
        $hiddenInputs = [];
        $action = (array)$action;
        if (!isset($url['@scheme'])) {
            $action['@scheme'] = Url::ABS;
        }
        $action = Url::modify($action);
        $request = Instance::ensure('request', '\rock\request\Request', [], false);
        if ($request instanceof Request) {
            if (strcasecmp($method, 'get') && strcasecmp($method, 'post')) {
                // simulate PUT, DELETE, etc. via POST
                $hiddenInputs[] = static::hiddenInput(
                    isset($name) ? $name . "[{$request->methodParam}]" : $request->methodParam,
                    $method,
                    ArrayHelper::getValue($options, 'hiddenMethod', [])
                );
                $method = 'post';
            }
        }

        $csrf = static::getCSRF();
        if ($csrf instanceof CSRF && $csrf->enableCsrfValidation && !strcasecmp($method, 'post')) {
            $token = $csrf->get();
            $hiddenInputs[] = static::hiddenInput(
                isset($name) ? "{$name}[_csrf]" : '_csrf',
                $token,
                ArrayHelper::getValue($options, 'hiddenCsrf', [])
            );
        }

        if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) {
            // query parameters in the action are ignored for GET method
            // we use hidden fields to add them back
            foreach (explode('&', substr($action, $pos + 1)) as $pair) {
                if (($pos1 = strpos($pair, '=')) !== false) {
                    $hiddenInputs[] = static::hiddenInput(
                        urldecode(substr($pair, 0, $pos1)),
                        urldecode(substr($pair, $pos1 + 1))
                    );
                } else {
                    $hiddenInputs[] = static::hiddenInput(urldecode($pair), '');
                }
            }
            $action = substr($action, 0, $pos);
        }
        unset($options['hiddenMethod'], $options['hiddenCsrf']);
        $options['action'] = $action;
        $options['method'] = $method;
        $form = static::beginTag('form', $options);
        if (!empty($hiddenInputs)) {
            $form .= "\n" . implode("\n", $hiddenInputs);
        }

        return $form;
    }
public static function beginForm($action = null, $method = 'post', $name = null, $options = [])
    {
        $hiddenInputs = [];
        $action = (array)$action;
        if (!isset($url['@scheme'])) {
            $action['@scheme'] = Url::ABS;
        }
        $action = Url::modify($action);
        $request = Instance::ensure('request', '\rock\request\Request', [], false);
        if ($request instanceof Request) {
            if (strcasecmp($method, 'get') && strcasecmp($method, 'post')) {
                // simulate PUT, DELETE, etc. via POST
                $hiddenInputs[] = static::hiddenInput(
                    isset($name) ? $name . "[{$request->methodParam}]" : $request->methodParam,
                    $method,
                    ArrayHelper::getValue($options, 'hiddenMethod', [])
                );
                $method = 'post';
            }
        }

        $csrf = static::getCSRF();
        if ($csrf instanceof CSRF && $csrf->enableCsrfValidation && !strcasecmp($method, 'post')) {
            $token = $csrf->get();
            $hiddenInputs[] = static::hiddenInput(
                isset($name) ? "{$name}[_csrf]" : '_csrf',
                $token,
                ArrayHelper::getValue($options, 'hiddenCsrf', [])
            );
        }

        if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) {
            // query parameters in the action are ignored for GET method
            // we use hidden fields to add them back
            foreach (explode('&', substr($action, $pos + 1)) as $pair) {
                if (($pos1 = strpos($pair, '=')) !== false) {
                    $hiddenInputs[] = static::hiddenInput(
                        urldecode(substr($pair, 0, $pos1)),
                        urldecode(substr($pair, $pos1 + 1))
                    );
                } else {
                    $hiddenInputs[] = static::hiddenInput(urldecode($pair), '');
                }
            }
            $action = substr($action, 0, $pos);
        }
        unset($options['hiddenMethod'], $options['hiddenCsrf']);
        $options['action'] = $action;
        $options['method'] = $method;
        $form = static::beginTag('form', $options);
        if (!empty($hiddenInputs)) {
            $form .= "\n" . implode("\n", $hiddenInputs);
        }

        return $form;
    }
public static function beginForm ( $ action = null , $ method = 'post' , $ name = null , $ options = [ ] ) { $ hiddenInputs = [ ] ; $ action = ( array ) $ action ; if ( ! isset ( $ url [ '@scheme' ] ) ) { $ action [ '@scheme' ] = Url :: ABS ; } $ action = Url :: modify ( $ action ) ; $ request = Instance :: ensure ( 'request' , '\rock\request\Request' , [ ] , false ) ; if ( $ request instanceof Request ) { if ( strcasecmp ( $ method , 'get' ) && strcasecmp ( $ method , 'post' ) ) { // simulate PUT, DELETE, etc. via POST $ hiddenInputs [ ] = static :: hiddenInput ( isset ( $ name ) ? $ name . "[{$request->methodParam}]" : $ request -> methodParam , $ method , ArrayHelper :: getValue ( $ options , 'hiddenMethod' , [ ] ) ) ; $ method = 'post' ; } } $ csrf = static :: getCSRF ( ) ; if ( $ csrf instanceof CSRF && $ csrf -> enableCsrfValidation && ! strcasecmp ( $ method , 'post' ) ) { $ token = $ csrf -> get ( ) ; $ hiddenInputs [ ] = static :: hiddenInput ( isset ( $ name ) ? "{$name}[_csrf]" : '_csrf' , $ token , ArrayHelper :: getValue ( $ options , 'hiddenCsrf' , [ ] ) ) ; } if ( ! strcasecmp ( $ method , 'get' ) && ( $ pos = strpos ( $ action , '?' ) ) !== false ) { // query parameters in the action are ignored for GET method // we use hidden fields to add them back foreach ( explode ( '&' , substr ( $ action , $ pos + 1 ) ) as $ pair ) { if ( ( $ pos1 = strpos ( $ pair , '=' ) ) !== false ) { $ hiddenInputs [ ] = static :: hiddenInput ( urldecode ( substr ( $ pair , 0 , $ pos1 ) ) , urldecode ( substr ( $ pair , $ pos1 + 1 ) ) ) ; } else { $ hiddenInputs [ ] = static :: hiddenInput ( urldecode ( $ pair ) , '' ) ; } } $ action = substr ( $ action , 0 , $ pos ) ; } unset ( $ options [ 'hiddenMethod' ] , $ options [ 'hiddenCsrf' ] ) ; $ options [ 'action' ] = $ action ; $ options [ 'method' ] = $ method ; $ form = static :: beginTag ( 'form' , $ options ) ; if ( ! empty ( $ hiddenInputs ) ) { $ form .= "\n" . implode ( "\n" , $ hiddenInputs ) ; } return $ form ; }
Generates a form start tag.

@param array|string $action the form action URL. This parameter
will be processed by {@see \rock\url\Url::getAbsoluteUrl()}.
@param string $method the form submission method, such as "post", "get", "put", "delete" (case-insensitive).
Since most browsers only support "post" and "get", if other methods are given, they will
be simulated using "post", and a hidden input will be added which contains the actual method type.
See {@see \rock\request\Request::$methodVar} for more details.
@param string|null $name name of form
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using {@see \rock\template\Html::encode()}.
If a value is null, the corresponding attribute will not be rendered.
See {@see \rock\template\Html::renderTagAttributes()} for details on how attributes are being rendered.
@return string the generated form start tag.
@see endForm()
Generates a form start tag .