将2个或更多参数从HTML表单传递给PHP函数 [英] Passing 2 or more parameters from a HTML form to a PHP function

查看:364
本文介绍了将2个或更多参数从HTML表单传递给PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个HTML表单,我需要将它的值作为参数发送给php函数,但我也需要一个不同的值,甚至不在HTML内。



例如:

 < form action =methods.phpmethod =register> 
< input type =textplaceholder =EventID>
< input type =submitvalue =Register>
< / form>

此表单将获取事件ID并将其作为参数发送,以便将用户注册到事件中。但我还需要将用户作为参数(函数注册表($ user,$ eventid))发送,我不知道如何操作。



我在这里找到了一些类似的东西,但它们与POST和GET有关,我不确定它们是否适用于我,而且我无法理解如何在它们中使用我的如果有人能够帮助我,pleaaaaaase,我会非常感谢你

可以为用户使用会话或cookie

 < form action =methods.phpmethod =post> 
< input type =hiddenname =txtuservalue =abc>
< input type =textplaceholder =EventID>
< input type =submitvalue =Register>
< / form>

如果您使用cookie或session,则不需要将它作为参数传递给它的全局变量您可以直接在任何页面访问其价值,您只需存储价值并在项目中的任何位置访问它。

So, I have a HTML form and I need to send it's value as a parameter to a php function, but I also need a different value, that's not even inside the HTML.

For example:

<form action="methods.php" method="register"> 
   <input type="text" placeholder="EventID"> 
   <input type="submit" value="Register"> 
</form>

This form would get the event id and send it as a parameter to register the user into the event. But I need to send the user as a parameter also (function register($user, $eventid)) and I have no idea on how to do so.

I did find some similar things around here, but they were related to POST and GET and I'm not sure they work for me and I could not understand how to use in them in my case, so if anyone could help me out, pleaaaaaase, i'd be really thankful

解决方案

you can use hidden field or you can use session or cookie for user

<form action="methods.php" method="post"> 
   <input type="hidden" name="txtuser" value="abc"> 
   <input type="text" placeholder="EventID"> 
   <input type="submit" value="Register"> 
</form>

if you use cookie or session then there is not need to pass it as parameter its a global variable so you can access its value at any page directly, you just need to store value to it and access it any where in your project.

这篇关于将2个或更多参数从HTML表单传递给PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆