从父窗口提交Iframe表单

时间:2013-03-03 08:57:47

标签: php javascript iframe

<iframe id="frame1" name="frame1" align="center" src="committee_assign1.php" height="400" width="700">
                </iframe>


                    <center><input onClick="submitiframeform(); return false;" type="button" name="submit" value="Submit" />
                <script type="text/javascript">

function submitiframeform(){
    window.frames['frame1'].document.forms['fypassign'].submit();
}
</script>

以上是主页面名称committee_assign.php ..

以下是iframe名为committee_assign1.php。

的页面
<?php
    include '../database.php';
    include 'valid_login.php';
       if(isset($_POST['submit'])) { 

    $continue = FALSE;
    $i = 0; 
    while ($continue == FALSE) { 
        if (isset($_POST['id_'.$i])) { 
            $fypcomm = $_POST['fypcomm_'.$i];
            $user = $_POST['id_'.$i];
            $sql = mysql_query(" UPDATE Lecturer SET LectFypCommittee = '$fypcomm' WHERE LectID = '$user' ") 
                or die(mysql_error());
            mysql_query($sql);
        } else
            {$continue = TRUE;}
        $i++;
    }

     echo ("<SCRIPT LANGUAGE='JavaScript'>

        window.location.href='../committee/committee_assign1.php'
        </SCRIPT>");

}

    ?>
<head>


</head>

<body>
<form id="fypassign" name="fypassign" method="post" action="" target="_self" onSubmit="">

                <?php


                $counter = 0;

                echo "<table class ='box'>";
                    echo "<thead>";
                    echo "<tr>";
                    echo "<th align='left' valign='top'>"."Lecturer Name"."</th>";
                    echo "<th align='left' valign='top'>"."FYP Committee"."</th>";    
                    echo "</tr>";

                    $sql = mysql_query(" SELECT * FROM Lecturer ORDER BY LectFypCommittee DESC, LectName ASC ") or die(mysql_error());
                    while($info = mysql_fetch_assoc($sql)) {
                        $idcount = "id_".$counter;
                        echo "<input type='hidden' name='$idcount' id='$idcount' value={$info['LectID']}  />";

                        echo "<tr>";

                        echo "<td>";
                            echo $info['LectName'];
                        echo "</td>";

                        echo "<td>";
                            $formname = "fypcomm_".$counter;
                            echo "<select name='$formname'>";
                            //to convert the flag value to user understandable language
                            if ($info['LectFypCommittee'] == '0'){
                                $dbfyp = 'No';
                            }
                            else $dbfyp = 'Yes';

                            echo "<option selected='selected' value='{$info['LectFypCommittee']}'>".$dbfyp."</option>";
                            if ($info['LectFypCommittee'] == '0'){
                                echo "<option value='1'>".'Yes'."</option>";
                            }
                            else echo "<option value='0'>".'No'."</option>";
                            echo "</select>";
                        echo "</td>";

                        echo"</tr>";
                        $counter++;
                    }

                    echo "</table>";
                ?>

                </form>

                </body>

我点击了父页面上的提交按钮和页面刷新,但值未更新。

有人可以在这指导我吗?

很抱歉发布这么长的代码,因为我希望你们能够理解我正在做的更多。 TQ

2 个答案:

答案 0 :(得分:0)

您的committee_assign.php中没有input名为submit:

if(isset($_POST['submit']))

你必须检查这样的事情:

if(isset($_POST))

答案 1 :(得分:0)

您正在检查提交是否已发布,但您没有名为“提交”的输入。添加一个名为submit的输入,其中包含一些值并检查该帖子是否存在。如果你不想看到额外的输入,你可以隐藏它。

if($ _ POST ['submit'])正在检查post数组中是否有值为'submit'的值。 $ _POST数组中的所有键和值分别是表单元素的名称和值。