douqilin4296 2012-03-21 20:44
浏览 31
已采纳

特殊字符缺失

I have a list of camera names in a html table. You can hit an edit button to edit the camera name if you wish.

This opens up a form (plus many other options) with the camera name now editable.

var edit = function(t, to, cameratype, cameraname, ...)
{
   var mydiv = js("#editform");

   if (mydiv.find("form").length) {
      mydiv.show();
   } else {
    // fields
    var $myform = js("<form id='EditCameraForm' name='' method='post' action='" + to + "'></form>");
    var $myfieldset = js("<fieldset><legend>Edit camera settings</legend></fieldset>");
    var $myinput = js("<input type='hidden' name='camera_type' value='" + cameratype + "' />");
    var $mylabel = js("<label for='CameraName'>Camera name:&nbsp;</label>");
    var $myinput2 = js("<input id='CameraName' name='camera_name' size='25' value='" + cameraname + "'  />");

    $myform.append($myinput, $mylabel, $myinput2, ...);
}

My problem is passing in cameraname. I allow special characters. So you can call the camera Joe's camera.

When I hit the edit button the camera name shows up as just Joe.

This has to do with my validation function in php when the camera name is first created...I believe:

function check_input($data)
{
            $data = trim($data);
            $data = stripslashes($data);
            $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
            $data = htmlentities($data, ENT_QUOTES, 'UTF-8');

            return $data;
 }

cameraname is passed in via the button click:

<button id="editbutton" onClick='edit(this, "<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>", "<?php echo $result_cameras[$i]["camera_type"]; ?>", "<?php echo $result_cameras[$i]["camera_name"]; ?>", ...)'>Edit</button>

If you view the page source of this it will show: Joe&#039;s camera. So I thought maybe I have to decode this in the JS code with decodeURIComponent(cameraname) but that doesn't work. Thanks for any help!

  • 写回答

2条回答 默认 最新

  • duanqiao3608 2012-03-21 20:56
    关注

    Instead of building your input boxes like you are, trying using a bit more Jquery.

    var $myinput = js('<input/>').attr('type','hidden').attr('name','camera_type').val(cameratype);
    

    Your problem is most likely you are creating a double quote issue in the value='" + cameratype + "' section.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分