The question emerges from the discussion with Christoph in my last question 'HTML: target=”_blank” for a drop-down list' and the alternative method by Andrew.
在我的上一个问题“HTML:target =”_ blank“下拉列表”和Andrew的替代方法中与Christoph的讨论中出现了这个问题。
Problem: to run code server-side because some users lack Javascript support. The situation is a form like here.
问题:运行代码服务器端,因为有些用户缺乏Javascript支持。情况就像这里一样。
Some suggestions:
Christoph's recommendation:
<form action="path-to-redirection-script" method="GET" target="_blank"
onsubmit="window.open(this.elements['foo'].value); return false;">
<select name="foo" size="1">
<option value="http://google.com">google</option>
</select>
<input type="submit" value="go">
</form>
安德鲁的替代方法:
<form onsubmit="this.js_enabled.value=1;return true;">
<input type="hidden" name="js_enabled" value="0">
<input type="submit" value="go">
</form>
Question: How would you do the server-side scripting in the case of form?
问题:在表单的情况下,您将如何执行服务器端脚本?
2 个解决方案
#1
Actually, it depends on the server-side language you're going to use.
实际上,它取决于您将要使用的服务器端语言。
But, it's as simple as reading out the values in the POST and GET Values the Form delivers you.
但是,它就像读取表格中提供的POST和GET值中的值一样简单。
i.e. PHP:
if($_POST["js_enabled"] == 0)
{
doSomething(); // Redirecting
}
But don't forget to validate all values.
但不要忘记验证所有值。
good luck,
rAyt
祝你好运,rAyt
Edit
There you go (pretty good answer though)
你去(虽然很好的答案)
How are POST and GET variables handled in Python?
如何在Python中处理POST和GET变量?
#2
There's no need for any additional code or checking for scripting on the server side: Because of the return false
in the onsubmit
handler, the form
won't be submitted if the handler is executed!
在服务器端不需要任何额外的代码或检查脚本:由于onsubmit处理程序中的返回false,如果执行处理程序,则不会提交表单!
Returning false
from event handlers supresses the default action associated with the event the same way as calling event.preventDefault()
(event.returnValue = false
in IE) does.
从事件处理程序返回false会以与调用event.preventDefault()(IE中的event.returnValue = false)相同的方式来抑制与事件关联的默认操作。
#1
Actually, it depends on the server-side language you're going to use.
实际上,它取决于您将要使用的服务器端语言。
But, it's as simple as reading out the values in the POST and GET Values the Form delivers you.
但是,它就像读取表格中提供的POST和GET值中的值一样简单。
i.e. PHP:
if($_POST["js_enabled"] == 0)
{
doSomething(); // Redirecting
}
But don't forget to validate all values.
但不要忘记验证所有值。
good luck,
rAyt
祝你好运,rAyt
Edit
There you go (pretty good answer though)
你去(虽然很好的答案)
How are POST and GET variables handled in Python?
如何在Python中处理POST和GET变量?
#2
There's no need for any additional code or checking for scripting on the server side: Because of the return false
in the onsubmit
handler, the form
won't be submitted if the handler is executed!
在服务器端不需要任何额外的代码或检查脚本:由于onsubmit处理程序中的返回false,如果执行处理程序,则不会提交表单!
Returning false
from event handlers supresses the default action associated with the event the same way as calling event.preventDefault()
(event.returnValue = false
in IE) does.
从事件处理程序返回false会以与调用event.preventDefault()(IE中的event.returnValue = false)相同的方式来抑制与事件关联的默认操作。