1

I need to use two forms on one page. When I click submit button on the first one - everything works fine. But when i click on the second one - POST returns array of 0 elements. What could be a problem?

first:

<form action="MAIN.php" method="POST">
    <input type="submit" name="Switch" value="<?php if ($_POST) { if ($_POST['Switch']=="Оперативный анализ данных") echo "Интеллектуальный анализ данных"; else echo "Оперативный анализ данных"; } else echo "Интеллектуальный анализ данных"; ?>">
    <input type="hidden" name="Report" value="GoodsPlace">
</form>

second:

<form action="MAIN.php" method="POST>
        <input type="hidden" name="Switch" value="Оперативный анализ данных">
        <select name="Report">
            <option <?php if ($_POST && $_POST['Report']=="GoodsPlace") echo "selected"?> value="GoodsPlace">Товар - Место</option>
            <option <?php if ($_POST && $_POST['Report']=="PlaceGoods") echo "selected"?> value="PlaceGoods">Место - Товар</option>
            <option <?php if ($_POST && $_POST['Report']=="TimeGoods") echo "selected"?> value="TimeGoods">Время - Товар</option>
            <option <?php if ($_POST && $_POST['Report']=="GoodsTime") echo "selected"?> value="GoodsTime">Товар - Время</option>
            <option <?php if ($_POST && $_POST['Report']=="PlaceTime") echo "selected"?> value="PlaceTime">Место - Время</option>
            <option <?php if ($_POST && $_POST['Report']=="TimePlace") echo "selected"?> value="TimePlace">Время - Место</option>
        </select>
        <input type="submit" name="submit" value="Показать">
    </form>
3
  • share you PHP code that you have written Commented May 27, 2013 at 23:43
  • 1
    <?php echo var_dump($_POST)?> returns array(0) { }, so i doubt there's a problem with php code. Commented May 27, 2013 at 23:45
  • <form action="MAIN.php" method="POST"> Commented May 27, 2013 at 23:49

3 Answers 3

2

Your HTML code is invalid:

<form action="MAIN.php" method="POST>

There is a missing double-quote after POST:

<form action="MAIN.php" method="POST">

It is likely to cause your form to fail.

Sign up to request clarification or add additional context in comments.

Comments

1

I think it just needs you to give each form a name. Example name=something and name=somethingelse to get rid of the problem.

Comments

0

On the submit, you could create a new form in javascript and join the two forms together (loop through child nodes) like this

var form = document.createElement("form");
form.method="post";
var forms = document.getElementsByTagName("form");
for(var i=0,j=forms.length; i<j; i++)
{
    for(var k=0,l<forms[i].childNodes.length; k<l; k++)
    {
        var node = forms[i].childNodes[k];
        if(node.name&&node.value!=null)
        {
            form.appendChild(node.parentNode.removeChild(node));//Move Node
        }
    }
}
form.submit();

Or, even better, on all inputs you want submitted, attach the class "tosubmit":

var form = document.createElement("form");
form.method="post";
var inputs = document.getElementsByClassName("tosubmit");
for(var i=0,j=inputs.length; i<j; i++)
{
    form.appendChild(inputs[i].parentNode.removeChild(inputs[i]));//Move Node
}
form.submit();

Source: Move nodes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.