I have a very simple form with three fields that I need to submit to an mvc action. The form must be application/x-www-form-urlencoded. however, one of the fields is populated by users copying and pasting an already urlencoded value. I would like to decode that value prior to submitting the form. this seems really simple but I keep running into proplems with my javascript.
我有一个非常简单的表单,有三个字段,我需要提交给一个mvc动作。表单必须是application / x-www-form-urlencoded。但是,其中一个字段由用户复制和粘贴已经urlencoded的值填充。我想在提交表单之前解码该值。这似乎很简单,但我一直在用我的javascript运行。
Here is the code:
这是代码:
<html>
<head>
<script>
function decodeURI()
{
decodeURIComponent(document.createprofile.URI.value);
}
</script>
<title>Test Create</title>
</head>
<body>
<center>
<h1> Spoof Profile Calls </h1>
<hr>
<div style="border: 1px solid black; width: 300px;">
<b>Create</b>
<form method="post" action="https://test.test-lab.com/Profile/Create/" name="createprofile">
<input type="hidden" name="ReturnURL" value="self.close()">
UserName: <input type="text" name="UserName"><br />
Client: <input type="text" name="Client"><br />
URI: <input type="text" name="URI" onblur="decodeURI();"><br />
<input type="submit" formenctype="application/x-www-form-urlencoded" value="Go To - Create"><br />
</form>
</div>
</body>
</html>
The URI field is the one that needs url decoded prior to submission because it gets reencoded and thus corrupted. I could ask the users to un-encode these values themselves but they are not terribly sophisticated users and it will likely not happen.
URI字段是在提交之前需要解码的URL字段,因为它被重新编码并因此被破坏。我可以要求用户自己对这些值进行解码,但它们不是非常复杂的用户,很可能不会发生。
Thank you in advance!
先感谢您!
UPDATED WITH FAILING CODE
更新失败的代码
1 个解决方案
#1
1
Replace the line
更换线
URI: <input type="text" name="URI" onblur="decodeURI();"><br />
by
URI: <input type="text" name="URI" onchange="decodeURI(this);"><br />
And do something like
并做一些类似的事情
function decodeURI(elm) {
elm.value = 'foo ' + elm.value + ' bar';
return false;
}
#1
1
Replace the line
更换线
URI: <input type="text" name="URI" onblur="decodeURI();"><br />
by
URI: <input type="text" name="URI" onchange="decodeURI(this);"><br />
And do something like
并做一些类似的事情
function decodeURI(elm) {
elm.value = 'foo ' + elm.value + ' bar';
return false;
}