0

ユーザー入力を許可するスニペット

//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
    if (e) {
               alertify.success("Form has been submitted");
               $.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+value, function( data ) {
           });

    }else{
       alertify.error("Your Form is not submitted");
    }
});

ユーザー入力:すべての Google 社員のための My Project Google R&D

フォームが投稿されると、入力は完了せず、次のように表示されます

echo $_POST['comment']My Project Google Rを印刷します

&ここで、ユーザーがコメントの ように特殊文字を入力すると、入力が壊れます

htmlentities($_POST['comment'])andを使用してみhtmlspecialchars($_POST['comment'], ENT_QUOTES, 'UTF-8')ましたが、機能しません。

ユーザーが特殊文字を入力できるようにするにはどうすればよいですか?

PS:この値をデータベースに保存していません

4

3 に答える 3

1

Daan が提案したよう&に、JavaScript で URL を分割します。Plsは私のために働いた更新されたスニペットを見つけます

//fetch user input and pass it in URL
alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) {
    if (e) {

               alertify.success("Form has been submitted");

               //encodes special characters in user comment
               var comment = encodeURIComponent(value);

               $.post(SITE_URL+"someController/someAction",$("#frm_submit").serialize()+ "&user_id="+user_id+"&comment="+comment, function( data ) {
           });

    }else{
       alertify.error("Your Form is not submitted");
    }
});
于 2015-07-02T06:55:39.103 に答える
0

これを試して:

stripslashes($_POST['comment'])
于 2015-07-02T06:44:31.207 に答える
0

post パラメータを使用してデータを送信します。

$.ajax({
  type: "POST",
  url: your_url,
  data: { user_id: user_id, comment: value } 
});
于 2015-07-02T06:43:38.880 に答える