gpt4 book ai didi

php - 没有 JavaScript 的非静态表单操作?

转载 作者:行者123 更新时间:2023-11-28 21:19:17 25 4
gpt4 key购买 nike

我有一个<form>action属性。

我想更改 action 的值基于 <input> 的值.

该值由用户提供。如果值为page1.php,则表单将提交至page1.php。如果值为page2.php,则表单将提交到page2.php,依此类推。

现在我正在使用 JavaScript 实现此目的,但是它无法在禁用 JavaScript 的浏览器上运行。

有什么办法可以让action没有 JavaScript 的非静态?

最佳答案

您无需调用任何 JavaScript 即可完成此操作。

PHP 示例;

<?php
/*if no destination was set previously the form will post back to itself*/
$action=isset($_Request['destination'])?$_Request['destination']:'';
?>
<form name='a-form-name' action="<?php echo $action;?>">

/*include other inputs etc as required.
Include a 'destination' input in _all_ forms involved.
You can of course name it whatever you like. But should always be the same name in all forms involved.
*/

<input type='hidden' name='destination' value='the-desired-destination-of-next-action'>

<input type='submit' name='whatever' value='Click here'>
</form>

当您按下提交按钮时,它将转到您在上次提交中设置的任何目的地或网址查询字符串中的“目的地”。

如果需要,您甚至可以使用变量使目标隐藏输入的值动态化。使用这种方法可以非常容易且广泛地进行分支。HTH

关于php - 没有 JavaScript 的非静态表单操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6808608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com