Hi
I'm facing a problem with having two forms in the same page.The problem is that the action is taken from only the first form.
For example :

<html>

<body>
<form action='test.php' method='POST'>
<input type='submit' />
</form>

<form action='testme.php' method='POST'>
<input type='submit' />
</form>

</body>

</html>

when I hit on submit (both buttons will send me to the page : test.php )!
so how can I make each form send me to it's page ?

I hope you were able to understand me.

Member Avatar for diafol

Can't see a problem. Tried your markup and it works fine for me.

DO you have a redirect (header) in the testme.php page?

redirect to where ?
No the two forms are sending me to the first page ,which is test.php in my example, even if it is empty !

Member Avatar for diafol

What do mean even if it's empty? There are no 'sent' fields in the forms.

code looks good to me and I tested locally as well and the action works as expected.

it is also working on my side.

What does the test.php and testme.php look like? Can you show the code?

It's working properly....

sorry , this is the original page :(index)

<?php session_start(); ?>
<?php require('inc/header.php'); 
?>
<body>
    <table cellspacing="9"  id='table_home'>
        <br /><br /><br /><br /><br />
            <form action="track.php" method="POST">
             <center>   <input type="text" name="track" placeholder="trace number" /> 
             <input class='submit' type="submit" value="Trace" /></center>
            </form>

        <tr>
        <td>
            <center><img src='images/Mouse.png'/></center>
            <b>test<b>
            <p>testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest </p>
        </td>
        <td>
            <center><img src='images/Phone.png'/></center>
            <b>test<b>
            <p>testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest </p>
        </td>
        <td>
            <center><img src='images/box.png'/></center>
            <b>test<b>
            <p>testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest</p>
        </td>
        </tr>
    </table>
</body>
<?php
require('inc/footer.php');
 ?>

The header page : (header.php)

<html>
<head>
    <title>test</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="inc/style.css"/>
    <link rel="shortcut icon" href="favicon.png" />
</head>
<header>
    <table>
        <tr>
        <td width="250">
            <img src="images/logo.png"/>
        </td>
        <td>
        <center>
        <div id='navbar'>
            <ul>
                <li><a href='index.php'>test</a></li>
                <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){echo "
                <li><a href='new_order.php'>test</a></li>
                <li><a href='profile.php'>test</a></li>
                <li><a href='contact.php'>test</a></li>  
                <li><a href='logout.php'>test</a></li>";
}else{
    echo"<li><a href='join.php'>Register</a></li>";
    echo "<form action='checklogin.php' method='POST'>
<lable>username</lable><input type='text' name='username' placeholder='username' />
<lable>password</lable><input type='password' name='password' placeholder='password' />
<input class='submit' type='submit' value='login' />
    </from>";
}

?>            
            </ul>
        </div>
        </center>
        </td>
        </tr>
    </table>
</header>

if I wasn't loged in then I'll have two forms :
1-login form
2-tracing form

Why dont use Ajax with <input type="button" onclick="ajaxfunction()" /> not submit?
ajaxfunction() is a javascript function. That function will call your php code.
Yours forms will be:

<form methos="POST">
    .....
    <input class='submit' type='button' value='login' onclick="Login()"/>
</form>


<form method="POST">
    .....
    <input class='submit' type="button" value="Trace" onclick="Tracing()"/>
</form>

You need after that some javascript code in your page

<script type = "text/javascript">

//This function create an Ajax object
//it's a standard function dont need to change it
    function getxmlhttp()
    {
        if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
            return new XMLHttpRequest();
        }
        else {
        // code for IE5, IE6
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }



    function Login()
    {
        var ajax = getxmlhttp();
        ajax.onreadystatechange = function() {
        if (ajax.readyState == 4 && ajax.status == 200) 
        {
            alert(ajax.responseText);
            //You can do what do you want with responseText
        }
    }
    ajax1.open("POST", "checklogin.php?parameters, true);
    ajax1.send();   

    }

    function Tracing()
    {
        var ajax = getxmlhttp();
        ajax.onreadystatechange = function() {
            if (ajax.readyState == 4 && ajax.status == 200) 
            {
                alert(ajax.responseText);
                //You can do what do you want with responseText
            }
        }
        ajax1.open("POST", "track.php?parameters, true);
        ajax1.send();   
    }

</script>

The ajax.responseText is filled by the echo and print php instructions.

I'll try it.Thanks

Member Avatar for diafol

This is probably your error:

echo "<form action='checklogin.php' method='POST'>
<lable>username</lable><input type='text' name='username' placeholder='username' />
<lable>password</lable><input type='password' name='password' placeholder='password' />
<input class='submit' type='submit' value='login' />
</from>";

You have a severe case of spelling tag names badly.
It's <label> and </form>

The last one is probably responsible for your problem - correct it. If you use a decent IDE this probably would not have occurred.

^Thanks man,that was my problem.Now my problem solved.Thank you guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.