简体   繁体   中英

How can i use more than 2 form in php and post values?

i want to ask how can i use more than 2 or 3 form in php? i have 2 different form with different id like"formid, formid2" and javascript control "kontrol(), kontrol2()". with this when i change selection the value of the selection appears from different form. But if the forms have same id and control it just appear first form's selection. How can i add and use values more than 2 - 3 forms?

Thanks.

<?php
if(isset($_POST['islem1']))
    echo "Value = " . $_POST['islem1'];

if(isset($_POST['islem2']))
    echo "Value = " . $_POST['islem2'];
?>
<html>
<head>
    <script>
        function kontrol(){

            document.getElementById("formid").submit();

        };

        function kontrol2(){

            document.getElementById("formid2").submit();

        };
    </script>
</head>
<body>
    <form action="two.php" method="post" id="formid">

        <select name="islem1" onchange="kontrol()">
            <option value="0">- - - - - -</option>
            <option value="1">1</option>
            <option value="2">2</option>
        </select>
    </form>

    <form action="two.php" method="post" id="formid2">

        <select name="islem2" onchange="kontrol2()">
            <option value="0">- - - - - -</option>
            <option value="10">10</option>
            <option value="20">20</option>
        </select>
    </form>

</body>
</html>

i will use this like these picture. it works for first row. all combobox are in a form seperate. if i add an entry and second row is adding too according to loop. so all forms have same ids and controls, after the first row the other combobox doesn't post anything.
http://www.imageupload.co.uk/Bhu --- First Image
http://www.imageupload.co.uk/Bhx --- Second Image

i found a way :). if i use variable, i can append forms as much as i want, it's like that,

<?php
if(isset($_POST['islem1']))
    echo "Value = " . $_POST['islem1'];


?>
<html>
<head>
    <script>
        function kontrol(i){

            document.getElementById("formid"+i).submit();

        };              

    </script>
</head>
<body>
    <?php for($i=1; $i<=3; $i++){ ?>
    <form action="two.php" method="post" id="formid<?php echo $i; ?>">

        <select name="islem1" onchange="kontrol(<?php echo $i; ?>)">
            <option value="0">- - - - - -</option>
            <option value="1">1</option>
            <option value="2">2</option>
        </select>
    </form>
    <?php } ?>

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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