Html::closeForm PHP Méthode

closeForm() static public méthode

Create a close form part including CSRF token
static public closeForm ( $display = true ) : String
$display boolean Display or return string (default true)
Résultat String
    static function closeForm($display = true)
    {
        global $CFG_GLPI;
        $out = "\n";
        if (GLPI_USE_CSRF_CHECK) {
            $out .= Html::hidden('_glpi_csrf_token', array('value' => Session::getNewCSRFToken())) . "\n";
        }
        if (isset($CFG_GLPI['checkbox-zero-on-empty']) && $CFG_GLPI['checkbox-zero-on-empty']) {
            $js = "   \$('form').submit(function() {\n         \$('input[type=\"checkbox\"][data-glpicore-cb-zero-on-empty=\"1\"]:not(:checked)').each(function(index){\n            // If the checkbox is not validated, we add a hidden field with '0' as value\n            if (\$(this).attr('name')) {\n               \$('<input>').attr({\n                  type: 'hidden',\n                  name: \$(this).attr('name'),\n                  value: '0'\n               }).insertAfter(\$(this));\n            }\n         });\n      });";
            $out .= Html::scriptBlock($js) . "\n";
            unset($CFG_GLPI['checkbox-zero-on-empty']);
        }
        $out .= "</form>\n";
        if ($display) {
            echo $out;
            return true;
        }
        return $out;
    }

Usage Example

 static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
 {
     echo "<form name='notificationtargets_form' id='notificationtargets_form'\n             method='post' action=' ";
     echo Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class    ='tab_cadre_fixe'>";
     echo '<tr><th colspan="2">' . __('Access type', 'formcreator') . '</th></tr>';
     echo '<td>' . __('Access', 'formcreator') . '</td>';
     echo '<td>';
     Dropdown::showFromArray('access_rights', array(PluginFormcreatorForm::ACCESS_PUBLIC => __('Public access', 'formcreator'), PluginFormcreatorForm::ACCESS_PRIVATE => __('Private access', 'formcreator'), PluginFormcreatorForm::ACCESS_RESTRICTED => __('Restricted access', 'formcreator')), array('value' => isset($item->fields["access_rights"]) ? $item->fields["access_rights"] : 1));
     echo '</td>';
     if ($item->fields["access_rights"] == PluginFormcreatorForm::ACCESS_RESTRICTED) {
         echo '<tr><th colspan="2">' . self::getTypeName(2) . '</th></tr>';
         $table = getTableForItemType(__CLASS__);
         $table_profile = getTableForItemType('Profile');
         $query = "SELECT p.`id`, p.`name`, IF(f.`plugin_formcreator_profiles_id` IS NOT NULL, 1, 0) AS `profile`\n                   FROM {$table_profile} p\n                   LEFT JOIN {$table} f\n                     ON p.`id` = f.`plugin_formcreator_profiles_id`\n                     AND f.`plugin_formcreator_forms_id` = " . (int) $item->fields['id'];
         $result = $GLOBALS['DB']->query($query);
         while (list($id, $name, $profile) = $GLOBALS['DB']->fetch_array($result)) {
             $checked = $profile ? ' checked' : '';
             echo '<tr><td colspan="2"><label>';
             echo '<input type="checkbox" name="profiles_id[]" value="' . $id . '" ' . $checked . '> ';
             echo $name;
             echo '</label></td></tr>';
         }
     }
     echo '<tr>';
     echo '<td class="center" colspan="2">';
     echo '<input type="hidden" name="profiles_id[]" value="0" />';
     echo '<input type="hidden" name="form_id" value="' . (int) $item->fields['id'] . '" />';
     echo '<input type="submit" name="update" value="' . __('Save') . '" class="submit" />';
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
 }
All Usage Examples Of Html::closeForm
Html