Jump to content

send form data to specific form id (PHP)


Nikolas96
 Share

Recommended Posts

hi, i have many forms in index.php file and i tried to send a form with method post from login.php file. and i use _$POST to receive data in specific section in index file. but all forms in index file submitted too.

what do i do? i want just my login form receive data and other forms still with no act...how i use form id in php receive codes to receive specific form data?

thanks...

Link to comment
Share on other sites

example php file with

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" id="viewport" content="target-densitydpi=high-dpi,initial-scale=1.0,user-scalable=no" />
        <title>Document Title</title>
    </head>
    <body>
        <?php
        $CurrentSent = FALSE;
        $test = "";
        if (isset($_POST['submit1'])) {
            $CurrentSent = TRUE;
        }

        if (isset($_POST['submit2'])) {
            $CurrentSent = TRUE;
        }

        if (isset($_POST['submit3'])) {
            $CurrentSent = TRUE;
        }

        if ($CurrentSent) {
            foreach ($_POST as $IndexName => $IndexNameValue) {
                echo $IndexName . ' : ' . $IndexNameValue . '<br>';
            }
            echo '<hr>';
        }
        ?>
        <form name="form1" action="#" method="POST">
            <input type="text" name="input1" value="Input#1" />
            <input type="submit" value="Submit#1" name="submit1" />
        </form>
        <form name="form2" action="#" method="POST">
            <input type="text" name="input2" value="Input#2" />
            <input type="submit" value="Submit#2" name="submit2" />
        </form>
        <form name="form3" action="#" method="POST">
            <input type="text" name="input1" value="Input#3" />
            <input type="submit" value="Submit#3" name="submit1" />

        </form>
    </body>
</html>

Even though form1 and form3 have exactly the same input name attributes, by submitting from specific individual form, you will only get that specific form inputs added to $_POST array.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...