user1114676
user1114676

Reputation: 51

Form does not submit

Good evening,

I have a form which is supposed to redirect me to cart.php but it is not working. Here is my code:

<tr align='center'>

            <td colspan='3'>
                <form method="post" action="cart.php">
                <input type="submit" name="action"  value="View Cart"/>
            <td>
        </tr>
        </form>
    </table>

When the button is clicked it remains in the current page. Any help please.. when i put the form at the end which means before the </body> it works. i have another form before this code which is this:

<form method='post' action='xbox.php'>

                <input type='hidden' name='isPostBack' value='true'/>
                <input type='hidden' name='productid' value='$row[ProductId]'/>
                <tr align='center'>
                    <td>
                        <input type='text' name='qty' class='inputtext'/>
                        <input type='submit' name='action' value='Buy now'/>
                        </form>

Is there a way to work the both forms and leave the first form before the second one?

Upvotes: 0

Views: 2272

Answers (3)

jeroen
jeroen

Reputation: 91792

Your html is incorrect, it should work when you put the closing form tag after the input:

    <td colspan='3'>
        <form method="post" action="cart.php">
            <input type="submit" name="action"  value="View Cart"/>
        </form>
    </td>

Your edited html does not validate either, so I would strongly recommend starting with valid html.

Anyway, although you are not showing all html, an additional problem could be that you have nested forms. You can have multiple forms on a page, but after each other, not nested. So this should work just fine:

<form method='post' action='xbox.php'>
...
</form>
...
<form method="post" action="cart.php">
    <input type="submit" name="action"  value="View Cart"/>
</form>

Upvotes: 11

Mike
Mike

Reputation: 1336

It's because you have tags intermingled. Sometimes it works because the parsers are somewhat forgiving, but it's not proper. Bring your tag under your input tag, and before your next tag (btw, your second td tag isn't closed, either)

Upvotes: 0

leepowers
leepowers

Reputation: 38318

The HTML is not well formed. It should be:

        <td colspan='3'>
            <form method="post" action="cart.php">
            <input type="submit" name="action"  value="View Cart"/>
            </form>
        <td>

Upvotes: 1

Related Questions