Html::submit PHP Method

submit() static public method

Creates a submit button element. This method will generate input elements that can be used to submit, and reset forms by using $options. Image submits can be created by supplying an image option
static public submit ( $caption, $options = [] ) : string
$caption caption of the input
$options Array of options. - image : will use a submit image input - `confirm` JavaScript confirmation message. - `confirmaction` optional action to do on confirmation
return string A HTML submit button
    static function submit($caption, $options = array())
    {
        $image = false;
        if (isset($options['image'])) {
            if (preg_match('/\\.(jpg|jpe|jpeg|gif|png|ico)$/', $options['image'])) {
                $image = $options['image'];
            }
            unset($options['image']);
        }
        // Set default class to submit
        if (!isset($options['class'])) {
            $options['class'] = 'submit';
        }
        if (isset($options['confirm'])) {
            if (!empty($options['confirm'])) {
                $confirmMessage = $options['confirm'];
                $confirmAction = '';
                if (isset($options['confirmaction'])) {
                    if (!empty($options['confirmaction'])) {
                        $confirmAction = $options['confirmaction'];
                    }
                    unset($options['confirmaction']);
                }
                $options['onclick'] = Html::getConfirmationOnActionScript($options['confirm'], $confirmAction);
            }
            unset($options['confirm']);
        }
        if ($image) {
            $options['title'] = $caption;
            $options['alt'] = $caption;
            return sprintf('<input type="image" src="%s" %s />', Html::cleanInputText($image), Html::parseAttributes($options));
        }
        return sprintf('<input type="submit" value="%s" %s />', Html::cleanInputText($caption), Html::parseAttributes($options));
    }

Usage Example

 /**
  * Show profile form
  *
  * @param $items_id integer id of the profile
  * @param $target value url of target
  *
  * @return nothing
  **/
 function showForm($profiles_id = 0, $openform = TRUE, $closeform = TRUE)
 {
     echo "<div class='firstbloc'>";
     if (($canedit = Session::haveRightsOr(self::$rightname, array(CREATE, UPDATE, PURGE))) && $openform) {
         $profile = new Profile();
         echo "<form method='post' action='" . $profile->getFormURL() . "'>";
     }
     $profile = new Profile();
     $profile->getFromDB($profiles_id);
     $rights = array(array('itemtype' => 'PluginAddressingAddressing', 'label' => __('Generate reports', 'addressing'), 'field' => 'plugin_addressing'));
     $profile->displayRightsChoiceMatrix($rights, array('canedit' => $canedit, 'default_class' => 'tab_bg_2', 'title' => __('General')));
     echo "<table class='tab_cadre_fixehov'>";
     $effective_rights = ProfileRight::getProfileRights($profiles_id, array('plugin_addressing_use_ping_in_equipment'));
     echo "<tr class='tab_bg_2'>";
     echo "<td width='20%'>" . __('Use ping on equipment form', 'addressing') . "</td>";
     echo "<td colspan='5'>";
     Html::showCheckbox(array('name' => '_plugin_addressing_use_ping_in_equipment[1_0]', 'checked' => $effective_rights['plugin_addressing_use_ping_in_equipment']));
     echo "</td></tr>\n";
     echo "</table>";
     if ($canedit && $closeform) {
         echo "<div class='center'>";
         echo Html::hidden('id', array('value' => $profiles_id));
         echo Html::submit(_sx('button', 'Save'), array('name' => 'update'));
         echo "</div>\n";
         Html::closeForm();
     }
     echo "</div>";
 }
All Usage Examples Of Html::submit
Html