php表单数据发送到两个不同的动作 [英] php form data send to two different action

查看:128
本文介绍了php表单数据发送到两个不同的动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我想发送表单数据到两个不同的动作,我可以在php中做到这一点

解决方案

我认为唯一的方法就是这样:

  if($ _ SERVER ['REQUEST_METHOD'] =='POST') {
switch($ _POST ['action']){
case'action1':
//做某事
break;
case'action2':
//做某事
break;




$ b $ p
$ b在你的表单中有一个隐藏的输入,其中将包含您想要执行的操作的类型。然后,在表单被提交后,您切换操作并执行所需操作。



另一种方式是,不使用PHP,将使用AJAX作为许多答案在相关的问题建议。


i have a form, i want to send form data to two different action, can I do that in php

解决方案

I think the only way would be something like this:

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    switch ($_POST['action']) {
        case 'action1':
             // do something
        break;
        case 'action2':
             // do something
        break;
    }
}

Where you would have a hidden input in your form, which would contain type of the action you want to do. Then after the form is submited, you switch the action and do what you need.

The only other way, without PHP, would be to use AJAX as many of the answers in related questions suggest.

这篇关于php表单数据发送到两个不同的动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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