如何在同一页面上放置两个表单? [英] How to place two forms on the same page?

查看:148
本文介绍了如何在同一页面上放置两个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将注册表和登录表单放在同一页面上。

它们都以

  if(!empty($ _ POST))... 

  if(!empty($ _ POST_01))... // regForm 

if (!empty($ _ POST_02))... // loginForm

另外如何防止执行first form如果第二个是忙的,反之亦然(用户点击两者)

我的想法是在启动过程中创建一个简单的变量,例如 $ x = 1 并且在过程 $ x = 0 结束时,所以:

 <$ c ($!$($ _ POST_01))$ x 

$ >可能有更好的方法。

解决方案

b

 < form action =login.phpmethod =post> 
< input type =textname =user>
< input type =passwordname =password>
< input type =submitvalue =Login>
< / form>

< br />

< form action =register.phpmethod =post>
< input type =textname =user>
< input type =passwordname =password>
< input type =submitvalue =Register>
< / form>

或者这样做

 < form action =doStuff.phpmethod =post> 
< input type =textname =user>
< input type =passwordname =password>
< input type =hiddenname =actionvalue =login>
< input type =submitvalue =Login>
< / form>

< br />

< form action =doStuff.phpmethod =post>
< input type =textname =user>
< input type =passwordname =password>
< input type =hiddenname =actionvalue =register>
< input type =submitvalue =Register>
< / form>

然后你的PHP文件将作为一个开关($ _ POST ['action'])...此外,他们无法同时点击两个链接或发出同时请求,每个提交都是一个单独的请求。

然后您的PHP将继续切换逻辑或有不同的PHP文件做登录程序,然后注册程序

I want to place both register and login form on the same page.
They both starts with:

if (!empty($_POST)) ... 

so, I need something like:

if (!empty($_POST_01))...  // regForm
  and 
if (!empty($_POST_02))...  //loginForm

Also how to prevent executing first form if the second is busy, and vice versa (user clicks on both)
My idea is to create a simple variable on starting process, for example $x = 1 and at the end of process $x = 0, so:

if ((!empty($_POST_01)) And $x = 0)...

Probably, there is a better way.

解决方案

You could make two forms with 2 different actions

<form action="login.php" method="post">
    <input type="text" name="user">
    <input type="password" name="password">
    <input type="submit" value="Login">
</form>

<br />

<form action="register.php" method="post">
    <input type="text" name="user">
    <input type="password" name="password">
    <input type="submit" value="Register">
</form>

Or do this

<form action="doStuff.php" method="post">
    <input type="text" name="user">
    <input type="password" name="password">
    <input type="hidden" name="action" value="login">
    <input type="submit" value="Login">
</form>

<br />

<form action="doStuff.php" method="post">
    <input type="text" name="user">
    <input type="password" name="password">
    <input type="hidden" name="action" value="register">
    <input type="submit" value="Register">
</form>

Then you PHP file would work as a switch($_POST['action']) ... furthermore, they can't click on both links at the same time or make a simultaneous request, each submit is a separate request.

Your PHP would then go on with the switch logic or have different php files doing a login procedure then a registration procedure

这篇关于如何在同一页面上放置两个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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