Cake\View\Helper\FormHelper::postButton PHP Method

postButton() public method

This method creates a
element. So do not use this method in an already opened form. Instead use FormHelper::submit() or FormHelper::button() to create buttons inside opened forms. ### Options: - data - Array with key/value to pass in input hidden - method - Request method to use. Set to 'delete' or others to simulate HTTP/1.1 DELETE (or others) request. Defaults to 'post'. - form - Array with any option that FormHelper::create() can take - Other options is the same of button method.
public postButton ( string $title, string | array $url, array $options = [] ) : string
$title string The button's caption. Not automatically HTML encoded
$url string | array URL as string or array
$options array Array of options and HTML attributes.
return string A HTML button tag.
    public function postButton($title, $url, array $options = [])
    {
        $formOptions = ['url' => $url];
        if (isset($options['method'])) {
            $formOptions['type'] = $options['method'];
            unset($options['method']);
        }
        if (isset($options['form']) && is_array($options['form'])) {
            $formOptions = $options['form'] + $formOptions;
            unset($options['form']);
        }
        $out = $this->create(false, $formOptions);
        if (isset($options['data']) && is_array($options['data'])) {
            foreach (Hash::flatten($options['data']) as $key => $value) {
                $out .= $this->hidden($key, ['value' => $value]);
            }
            unset($options['data']);
        }
        $out .= $this->button($title, $options);
        $out .= $this->end();
        return $out;
    }