简体   繁体   English

一种表格/提交两种动作

[英]One Form/Submit Two Actions

I have a bit of a problem with my website. 我的网站有问题。 I have phpbb integrated into my website and a login form on the homepage. 我已经将phpbb集成到我的网站中,并在主页上登录了表单。 This form needs to execute two different actions. 该表格需要执行两个不同的动作。 It first needs to run the ucp.php (to log into phpbb) and also the login.php (to hide the form and add control panel on home screen). 它首先需要运行ucp.php(登录到phpbb)以及login.php(隐藏表单并在主屏幕上添加控制面板)。 They both work by themselves, I just need a way to have them together when a user logs in. i have researched this for a while and can't find a solution. 它们都可以单独工作,当用户登录时,我只需要一种将它们组合在一起的方法。我已经研究了一段时间,但找不到解决方案。 Thanks in advances, Josh 预先感谢,乔希

I need to combine this 我需要结合一下

<form action="./forums/ucp.php?mode=login" method="post" enctype="multipart/form-data"> 

with this 有了这个

<form action="login.php" method="post" enctype="multipart/form-data"> 

I think you have a serious design issue in your code if you have to "merge" stuff like that, but in any case: 我认为,如果您必须“合并”这样的内容,那么代码中就会出现严重的设计问题,但是无论如何:

Just create a new file ie. 只需创建一个新文件即可。 post_handler.php and toss this code in it: post_handler.php并在其中抛出以下代码:

<?php
include('forums/upc.php');
include('login.php');
?>

Place it in the same directory as login.php. 将其放置在与login.php相同的目录中。

Then adjust your form to point to post_handler.php?mode=login . 然后调整表格以指向post_handler.php?mode=login

Ofcourse merging files like that could result in crazy unexpected results.. 当然,像这样合并文件可能会导致疯狂的意外结果。

Another option, though more complex, would be to use the login.php as your action and do a curl request to forums/ucp.php inside it. 另一个选择(尽管更复杂)是使用login.php作为操作,并向其中的forums/ucp.php发出curl请求。 (search for Curl on php.net documentation) (在php.net文档中搜索Curl)

Unfortunately I can not give more suggestions, because what you are trying to do is probably more complex then something that can easily be answered here. 不幸的是,我无法提供更多建议,因为您要尝试做的事情可能比此处容易回答的问题更为复杂。

Well you can try trick with ajax. 好吧,您可以尝试使用Ajax。 Here is an example that should work with jquery: Im not sure if preventDefaut() wont make us a problem here and we still be allowed to use .submit() on it. 这是一个应该与jquery一起使用的示例:不知道是否preventDefaut()在这里不会给我们带来麻烦,我们仍然可以在其上使用.submit()。 If it wont work. 如果不行。 Try to put whole thing into function, remove preventDefault and bind this function into submit button. 尝试将全部内容放入函数中,删除preventDefault并将此函数绑定到Submit按钮。

<form id="form_id" action="login.php" method="post" enctype="multipart/form-data">
User name: <inputy type="text" id="username" name="username" />

</form>

<script type="text/javascript">
    $(function() {
      //we prevent normal form submit
      $('#form_id').preventDefault();
      var data = {} ;
          //here u build data u want send by taking it from form field by field
      //example
      data['username'] = $('#username');

          //and you send this data via ajax to your upc script
          $.ajax({
        type: "POST",
        url: '/forums/ucp.php?mode=login',
        data: data,
                //in case of succes we send form normal way
        success: function( xhr ) { $('#form_id').submit(); },
        dataType: String
        });

    });

<script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM