0

子ページを呼び出してフォームを投稿しています。子ページに入力された値に基づいて、親ページを更新して再構築しようとしています。親ページに子が投稿した値が表示されません。

子が親ページから送信されると、期待値 $_POST['test_2'] が入力されます。子ページによって投稿された値が親ページに表示されません。以下のコード例を参照してください。助けてくれてありがとう。

親ページ: Example1Parent.php

<html>
<head>
<body>
<h1> Welcome Parent </h1>
<div id="dateDiv"></div>
<form method=post action='' name=f1>
<table border=0 cellpadding=0 cellspacing=0 width=550>
<tr>
<td ><font size=2 face='Verdana'>Refresh upon Search</font>
<input type=hidden name='p_name2' id=n2 size='8'> 
<input type=button 
onClick=window.open("Example1Child.php","Ratting","width=550,height=170,left=150,top=200,toolbar=0,status=0,"); value="Advanced Search">
<?php
echo '<br> Welcome ';
if (!isset($_POST['test_2'])) echo "<br> t_test2 : it does not exists! ";
?>
</td></tr> 
</table>
</form>
</body>
</html>

子ページは :Example1Child.php

 <html>
 <head>
 <title>ChildForm</title>

 <SCRIPT language=JavaScript>
 <!-- 
 function win(){
 window.opener.location.href="Example1Parent.php";
 self.close();
 //-->
 }
</SCRIPT>
</head>
<body>
<h1> Welcome to Child </h1>
<form name="child"  id="child"  METHOD="POST" action=''>
<input type="text" id="test_2" name="test_2" value="ENTER DATA TO PARENT PAGE">
<INPUT TYPE="SUBMIT" onClick="win();" value="SEND VALUE TO PARENT">
</form>

</body> 
</html>
4

1 に答える 1

0

tmuguet が述べたように、これはかなり古い方法であるため、別の方法を作成することをお勧めします。今では、ポップアップ/モーダルボックスなどを使用して値を取得し、js/ajax などでページを更新できます。

js を介してウィンドウを介して値を渡そうとしていると思いますが、ウィンドウを開いてクリーンなリンクを開くため機能しません (フォーム メソッドに「POST」がある場合でも値が渡されません)。次のようなものを使用できます。以下ですが、GET値のみを提供します

<SCRIPT language=JavaScript>
<!-- 
    function win(){
        val = document.getElementById('test_2').value;//you will most likely need to encode this value if it has special characters
        window.opener.location.href="Example1Parent.php?test_2=" + val;
        self.close();
//-->
}
</SCRIPT>

あなたが探しているのは、Window.openのようなもので、ポストメソッドの問題でパラメーターを渡します

<form id="child" method="post" action="Example1Parent.php" target="Parent">
    <!-- <form name="child"  id="child"  METHOD="POST" action=''> -->
    <input type="text" id="test_2" name="test_2" value="ENTER DATA TO PARENT PAGE">
    <INPUT TYPE="SUBMIT" onClick="win();" value="SEND VALUE TO PARENT">
</form>

<script type="text/javascript">
    function win(){
        var f = document.getElementById('child');
        f.test_2.value =  document.getElementById('test_2').value;
        window.open('Example1Parent.php', 'Parent');
        f.submit();
        self.close();
    }
</script>

このスクリプトはテストしていません

var_dump($_POST)Example1Parent.php ファイルで を実行してf.test_2.value$_POST['test_2']

于 2013-02-03T21:45:40.507 に答える