douhe4608 2014-10-24 09:41
浏览 31

通过隐藏表单将变量发布到其他页面?

I post this here for 2 reasons: -to make sure that there is no problem with the trick, and -to share the idea, in case it is OK

I thought it as a way to post to different pages, according to different tasks available to the user. I find this trick with forms easy to implement and i made extensive use of it in a project (a beginner writing!) and it seems to work perfectly (locally testing). But i did not find it clearly suggested anywhere, so i wonder if there is any potential problem with this code. Is it "legitimate" coding really?

Part 1 (visible)

<a href="" onclick="document.form1.submit();return false;">case 1</a><br />
<a href="" onclick="document.form2.submit();return false;">case 2</a>

Part 2 (invisible, at least some form(s))

<form style="display:none;" name="form1" method="post" action="page1.php">
<input type="hidden" name="v1" id="v1" value="<?="form 1 - value 1..."?>" />
<input type="hidden" name="v2" id="v2" value="<?="form 1 - value 2..."?>" />
</form>

<form style="display:none;" name="form2" method="post" action="page1.php">
<input type="hidden" name="v1" id="v1" value="<?="form 2 - value 1..."?>" />
<input type="hidden" name="v2" id="v2" value="<?="form 2 - value 2..."?>" />
</form>

In the visible part, any elements that accept onclick can be used, for example:

<input type="Submit this" value="process 1..." onclick="document.form1.submit();" />
<input type="Submit that" value="process 2..." onclick="document.form2.submit();" />

What seems to make this invaluable is that they can lead to different pages and with different variables:

<form style="display:none;" name="form1" method="post" action="page1.php">...</form>
<form style="display:none;" name="form2" method="post" action="page2.php">...</form>

If the answer is rather negative, would it be wise to start practicing on storing values temporarily in the database? I read that, theoretically, it is the safest way, but is this true?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)