简体   繁体   English

我有3个表单和一个提交按钮,我只是从1个表单接收信息

[英]I have 3 forms and one submit button and I am just receiving information from 1 form

I am putting information in my forms and I'm just receiving 1 from the form number 3 not the others. 我将信息放入表格中,而我只是从表格编号3中收到1,而不是其他表格。

Here is my code in the page 这是我在页面中的代码

What should I do to solve this problem? 我该怎么做才能解决这个问题? Could someone please helps me out with this.. 有人可以帮我这个忙..

// my code to the forms in the page
  <div style="margin-left:110px;float:left !important ;clear:both;">
<?php

echo '
<form method="post" action="testing.php" id="form1">
<textarea style="height:150px;width:250px;" name="message"></textarea>

</form>
';
?>
</div>
<div>
<?php

echo '
<form method="post" action="testing2.php" id="form2">
<textarea style="margin-left:80px;height:150px;width:250px;" name="message">Write your opinon here</textarea>

</form>
';
?>

</div>
<div>

<?php
echo '
<form method="post" action="testing3.php" id="form3">
<textarea style="margin-left:80px;height:150px;width:250px;" name="message"></textarea>

</form>
';
?>
</div>

My javascript for the forms: 我的形式的JavaScript:

 <script>
            submitForms = function() {
                document.forms["form1"].submit();
                document.forms["form2"].submit();
                document.forms["form3"].submit();
                return true;
            }
        </script>

<input type="button" value="submit" onclick="submitForms()" />

and the php code for my forms is below (I have the same code for the other forms): 和我的形式的PHP代码如下(我对其他形式有相同的代码):

//php code to connect to mysql



<?php
$message=$_POST['message'];
$con=mysqli_connect();
$sql="insert into textarea values('$message')";
if(mysqli_query($con,$sql))
{echo "Thanks for your opinoin";}
?>
<!DOCETYPE html>
<html>
<head>
<style>

body {

    text-align:center;
padding-top:300px;
font-size:40px;
color:white;
font-style:oblique;

}


</style>
</head>

<body background="hero.jpg" text="">
<?php

    ?>
    </body>
    </html>

What should I do?? 我该怎么办??

You have 3 separate forms, and only first .submit() in javascript works. 您有3种不同的形式,并且只有javascript中的第一个.submit()有效。 Either merge everything to one form(you still can have 3 buttons and check what is pressed) or write ajax code what submit 3 different forms. 要么将所有内容合并到一个表单(您仍然可以拥有3个按钮并检查所按的内容),要么编写提交3种不同表单的ajax代码。

Your Code was Correct if you use this code: 如果您使用以下代码,则您的代码是正确的:

<script>
            submitForms = function() {
                document.forms["form1"].submit();
                document.forms["form2"].submit();
                document.forms["form3"].submit();
                return true;
            }
        </script>

<input type="button" value="submit" onclick="submitForms()" />

your html form should like this code : 您的html表单应类似于以下代码:

<form method="post" action="testing1.php" name="form1">
<form method="post" action="testing2.php" name="form2">
<form method="post" action="testing3.php" name="form3">

Or You can use like this code: 或者您可以使用像这样的代码:

submitForms = function(){
    document.getElementById("form1").submit();
    document.getElementById("form2").submit();
    document.getElementById("form3").submit();
}

your code's action links reference to three different locations, plus each form needs to have a unique submit button. 您的代码的操作链接引用了三个不同的位置,此外,每个表单都需要有一个唯一的提交按钮。 if you need to get the inputs of each form then set an id for that submit button and the in your php code check if it's set. 如果您需要获取每种形式的输入,则为该提交按钮设置一个ID,并在php代码中检查是否已设置。 like so: 像这样:

<form method="post" action="testing2.php" id="form2">
<textarea name="textarea"></textarea>
<input type="submit" value="submit btn" id="submit_id">
</form>

then in php do something like this: 然后在php中执行以下操作:

if(isset($_POST['submit_id'])){

}

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

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