PHP Post Regex,需要摆脱百分比符号

时间:2015-12-15 02:22:45

标签: javascript regex

感谢您的时间。

我的代码存在轻微问题。

我使用表单创建了两个用于更新PHP数据库的文件。

post值很好,并在输入字段中分配变量。

我的问题是我的网址如下:

  

http://localhost/GigaWatt/database/update_specs.php?id=8&cpu=i7-4470K&gpu=Geforce%20Titan%20X&psu=1500&motherboard=Asrock%20X99%20Extreme4&mouse=Razer%20Naga&keyboard=%20Razer%20Arctosa&monitor=LG%2031MU97-B&price=12000

我的表单如下:

http://i.imgur.com/1Jd0llm.jpg

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Update Specs DB</title>
    <script>
        function getURLValue(name)
        {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.href);
            if (results === null)
                return null;
            else
                return results[1];
        }
    </script>
 </head>

 <form action="update_transaction.php" method="post">

    <label for="id">ID: </label>
    <input type="number" id = "id" name = "id" required><br>

    <label for="cpu">Processor: </label>
    <input type="text" id = "cpu" name = "cpu" required><br>

    <label for="gpu">Graphics Card: </label>
    <input type="text" id = "gpu" name = "gpu" required><br>

    <label for="psu">Power Supply (Watts): </label>
    <input type="number" id = "psu" name = "psu" value = "0" min = "300" max="2000" required><br>

    <label for="motherboard">Motherboard: </label>
    <input type="text" id = "motherboard" name = "motherboard" required><br>

    <label for="mouse">Mouse: </label>
    <input type="text" id = "mouse" name = "mouse" required><br>

    <label for="keyboard">Keyboard: </label>
    <input type="text" id = "keyboard" name = "keyboard" required><br>

    <label for="monitor">Monitor: </label>
    <input type="text" id = "monitor" name = "monitor" required><br>

    <label for="price">Price: </label>
    <input type="number" id = "price" name = "price" required><br>     

    <input id="submit" type="submit" value="Add Record">

  </form>

   <script>
    if (getURLValue('id') !== null)
    {
        document.getElementById('id').value = getURLValue('id');
        document.getElementById('cpu').value = getURLValue('cpu');
        document.getElementById('gpu').value = getURLValue('gpu');
        document.getElementById('psu').value = getURLValue('psu');
        document.getElementById('motherboard').value = getURLValue('motherboard');
        document.getElementById('mouse').value = getURLValue('mouse');
        document.getElementById('keyboard').value = getURLValue('keyboard');
        document.getElementById('monitor').value = getURLValue('monitor');
        document.getElementById('price').value = getURLValue('price');
     }
  </script>

</body>
</html>

如何摆脱&#34;%20&#34;在URL中或处理后所有文本看起来是否清除?

0 个答案:

没有答案