PMA\libraries\Sanitize::jsFormat PHP Method

jsFormat() public static method

.., ). This function is used to displays a javascript confirmation box for "DROP/DELETE/ALTER" queries.
public static jsFormat ( string $a_string = '', boolean $add_backquotes = true ) : string
$a_string string the string to format
$add_backquotes boolean whether to add backquotes to the string or not
return string the formatted string
    public static function jsFormat($a_string = '', $add_backquotes = true)
    {
        $a_string = htmlspecialchars($a_string);
        $a_string = Sanitize::escapeJsString($a_string);
        // Needed for inline javascript to prevent some browsers
        // treating it as a anchor
        $a_string = str_replace('#', '\\#', $a_string);
        return $add_backquotes ? Util::backquote($a_string) : $a_string;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Outputs HTML for forms
  *
  * @param bool   $tabbed_form          if true, use a form with tabs
  * @param bool   $show_restore_default whether show "restore default" button
  *                                     besides the input field
  * @param bool   $show_buttons         whether show submit and reset button
  * @param string $form_action          action attribute for the form
  * @param array  $hidden_fields        array of form hidden fields (key: field
  *                                     name)
  *
  * @return string HTML for forms
  */
 public function getDisplay($tabbed_form = false, $show_restore_default = false, $show_buttons = true, $form_action = null, $hidden_fields = null)
 {
     static $js_lang_sent = false;
     $htmlOutput = '';
     $js = array();
     $js_default = array();
     $htmlOutput .= PMA_displayFormTop($form_action, 'post', $hidden_fields);
     if ($tabbed_form) {
         $tabs = array();
         foreach ($this->_forms as $form) {
             $tabs[$form->name] = PMA_lang("Form_{$form->name}");
         }
         $htmlOutput .= PMA_displayTabsTop($tabs);
     }
     // validate only when we aren't displaying a "new server" form
     $is_new_server = false;
     foreach ($this->_forms as $form) {
         /* @var $form Form */
         if ($form->index === 0) {
             $is_new_server = true;
             break;
         }
     }
     if (!$is_new_server) {
         $this->_validate();
     }
     // user preferences
     $this->_loadUserprefsInfo();
     // display forms
     $htmlOutput .= $this->_displayForms($show_restore_default, $js_default, $js, $show_buttons);
     if ($tabbed_form) {
         $htmlOutput .= PMA_displayTabsBottom();
     }
     $htmlOutput .= PMA_displayFormBottom();
     // if not already done, send strings used for validation to JavaScript
     if (!$js_lang_sent) {
         $js_lang_sent = true;
         $js_lang = array();
         foreach ($this->_jsLangStrings as $strName => $strValue) {
             $js_lang[] = "'{$strName}': '" . Sanitize::jsFormat($strValue, false) . '\'';
         }
         $js[] = "\$.extend(PMA_messages, {\n\t" . implode(",\n\t", $js_lang) . '})';
     }
     $js[] = "\$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})';
     $htmlOutput .= PMA_displayJavascript($js);
     return $htmlOutput;
 }
All Usage Examples Of PMA\libraries\Sanitize::jsFormat