0

我的 JQuery 没有启动清理功能。我需要从输入字段名称中获取值,对其进行清理(使用清理功能)并将其显示在路径输入字段中。为什么它不起作用?我使用 PHP 5.3 和 HEIDISQL

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php 

    include('conect.php');
    if(($_POST)&&(!empty($_POST['name']))&&(!empty($_POST['path'])) ){
    $name=$_POST['name'];
    $path=$_POST['path'];

    function sanitize($title) {
        $title = strip_tags($title);
        // Preserve escaped octets.
        $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
        // Remove percent signs that are not part of an octet.
        $title = str_replace('%', '', $title);
        // Restore octets.
        $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);

        if (seems_utf8($title)) {
            if (function_exists('mb_strtolower')) {
                $title = mb_strtolower($title, 'UTF-8');
            }
            $title = utf8_uri_encode($title, 200);
        }

        $title = strtolower($title);
        $title = preg_replace('/&.+?;/', '', $title); // kill entities
        $title = str_replace('.', '-', $title);
        $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
        $title = preg_replace('/\s+/', '-', $title);
        $title = preg_replace('|-+|', '-', $title);
        $title = trim($title, '-');

        return $title;
    }   

    mysql_query("UPDATE menus SET name='$name' , path='$path'");
    }

    ?>
    <html>
    <head>

    <script>


$(document).ready(
function(){
          $("#name").change(function(){
             $("#path").sanitize("name").val();             

          });
} );


</script>

    </head>

    <body>
            <form action="<?php $_PHP_SELF ?>" method="post">
            <label for="nume">Name</label><input type="text" name="name" />
            <label for="cale">Path</label><input type="text" name="path" />
            <input type="submit" name="submit"/>
    </form>
    </body>
    </html>
4

2 回答 2

1

因为其余的是 PHP 代码,您可以将其作为 Javascript 运行

于 2013-01-14T13:27:31.047 回答
1

它不起作用,因为它是用 PHP 编写的,并且您正试图在客户端运行它,就好像它是 JavaScript 一样。

您不能相信客户端会向您发送经过清理的数据——您无法控制客户端。

于 2013-01-14T13:28:42.057 回答