php - 一种 PHP 表单中的两种表单操作

标签 php javascript html

我的 php 代码有两个问题。

第一个是变量如何

$linkorig

之后可以看到

$_POST['formsubmitted']

,当我从重定向页面获取它时?

第二个问题是,在完成错误检查之后,如何使用不同的操作进行表单提交?

也许可以使用一些 javascript 或 php 代码。

<?php
    $linkorig=$_POST['link-orig']; // get destination link from redirected page , for excample http://mikrotik.lv -- works fine 
    if (isset($_POST['formsubmitted'])) 
    {
        // script try login with credentials  with  <form action="login.php"   --- works fine
        //Error checking !
        if (empty($error)) //if not found any errors {
            // login with credentials and same form but  with  <form action="other_login.php"   --- i dont know how to do :(
        }
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Login Form</title>
    </head>
    <body>
        <form name="login"  action="login.php"  method="post" class="registration_form" onSubmit="return doLogin()" >
            <input type="hidden" name="dst" value="<?php echo $linkorig; ?>" />
            <input type="hidden" name="popup" value="true" />
            <fieldset>
                <legend>Login Form  </legend>
                <p>Enter Your username and Password Below  </p>
                <div class="elements">
                    <label for="name">Email :</label>
                    <input type="text" id="e-mail" name="username" size="25" value="" />
                </div>
                <div class="elements">
                    <label for="Password">Password:</label>
                    <input type="password" id="Password" name="password" size="25" />
                </div>
                <div class="submit">
                    <input type="hidden" name="formsubmitted" value="TRUE" value="OK" />
                    <input type="submit" value="Login" />
                </div>
            </fieldset>
        </form>
        <!-- $(if error) -->
            <br /><div style="color: #FF8080; font-size: 9px"> </div>
        <!-- $(endif) -->
        <script type="text/javascript">
            <!--
            document.login.username.focus();
            //-->
        </script>
    </body>
</html>

最佳答案

您可以轻松地使用一个表单执行 2 个操作:

<form method='post' action='post.php'>
<input type='text' name='field1' />
<input type='text' name='field1' />

<button name='action1'>action1</button>
<button name='action2'>action2</button>
</form>

在页面 post.php 上:

所有变量都将位于 $_POST 中,即 $_POST['field1']、$_POST['field2']、$_POST['action1'] 和 $_POST[ ' Action 2'] 使用简单的条件:

if(isset($_POST['action1'])) {
  //some code here but still check action2

  // edit : you can call the action2 with jquery and [ajax][1]
  // you can use header('location: http://example.com?field1='.$_POST['field1'].'&field2='.$_POST['field1']) to redirect, but no output before using header => see ob_get_clean() if you have any problem.
}
else { exit; } //stop it all if action1 failed
<小时/>

但是,如果您重定向页面,则不再有 $_POST 变量。您可以使用 /page.php?var1=... 和 $_GET 它们,就像使用 $_POST 一样。

关于php - 一种 PHP 表单中的两种表单操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713432/

相关文章:

php - 如何使用 html 文件选择器(输入类型 ="file")将照片上传到 facebook(graph api)

javascript - Angular 自定义指令范围未按预期更新

javascript - Ajax 不适用于 javascript。我应该做些什么?

javascript - 从链接打开本地文件夹

javascript - 如何将html页面设置为背景图片?

php - 使用联接的 Sql 查询

php - 拆分多行并将它们输入到数据库中的单独行中

php - 如何在 select 命令中选择表的主索引作为列

javascript - Google 地球气球重新加载 - 客户端和插件

javascript - 尝试从多维数组中删除项目(html、javascript)