0

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

karauzum
  • 81
  • 7
  • are you allowed to use jQuery? – anurupr Feb 10 '14 at 13:05
  • 4
    "But if the forms have same id..." Please don't give multiple elements the same `id`. By definition, `id`s are meant to be unique. – ChrisGPT was on strike Feb 10 '14 at 13:06
  • You could or youse hust one form but let it look as different forms with css... Or you use JS an FormData Object eg: http://stackoverflow.com/questions/6974684/how-to-send-formdata-objects-with-ajax-requests-in-jquery – Martin Feb 10 '14 at 13:09
  • i can use jquery if it solve the prob. The forms append according to adding entry and a loop adds rows with forms – karauzum Feb 10 '14 at 14:14

1 Answers1

0

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>
karauzum
  • 81
  • 7