Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   To send the form values of a child window to a parent window (http://www.go4expert.com/forums/send-form-values-child-window-parent-t9082/)

rekha 28Feb2008 12:29

To send the form values of a child window to a parent window
 
Hi

I have a main form with a hidden variable in a parent php page.When i click a link in this page a popup window opens.In that popup window I have a form and the form action is self page.I have posted the form variables and stored it in php variables in the child form.I had set the value for the hidden variable of the parent page as an array of posted values in the child window using javascript.

Now If i submit the child form by clicking the submit button the values are not assigned to the hidden field of the parent page.If i click the submit form twice the values are assigned to the hidden variable.
I want the child form to submit only once and the values are set to the hidden field of the parent page when the child form submit button is clicked only once.How can i do this?


Regards
Rekha

pradeep 28Feb2008 13:48

Re: To send the form values of a child window to a parent window
 
Can you some code snippet so that we have a better idea of how you are doing it??

rekha 29Feb2008 12:10

Re: To send the form values of a child window to a parent window
 
Hi

I have a form in parent php page

Code:

Code:

<form name=add>
<input type=hidden name=cus>
</form>


In child window i have a form like this
Code:

Code:

<form name=sub method=post action="<?php echo $PHP_SELF;?>" onsubmit="jss()">
<input type=text name=ss>
<input type=text name=cc>
<input type=submit value=run>
</form>

I have posted the values and stored it in a array as follows
Code:

$ss=$_POST['ss'];
$cc=$_POST['cc'];
$array=array($ss,$cc);


I used javascript function to set the array values to the hidden field in parent window.
Code:

Code:

function jss()
{
window.opener.document.add.cus.value="<?php echo base64_encode(serialize($array));?>";
}


When i post the values of hidden field in parent window
Code:

Code:

$arr=unserialize(base64_decode($_POST['cus']));


The values are assigned when i click the submit button of the child window twice.I want to set the values when submit button is clicked only once.

Pls help........

Regards
Rekha

pradeep 29Feb2008 13:17

Re: To send the form values of a child window to a parent window
 
Hi rekha,
You are calling the function jss() while submitting the child form, the data is not being set because the php variable $array is only available only after submitting the form, so its of no use calling the function jss() when submitting the form.
As a result of this, when you submit the child form the 2nd time, the value is set to parent window.

rekha 29Feb2008 15:20

Re: To send the form values of a child window to a parent window
 
Hi pradeep

Thanks for your reply.Then how can i do this.



Regards
Rekha

pradeep 29Feb2008 18:39

Re: To send the form values of a child window to a parent window
 
Thi child page's code should look something like this, you need to call the JS function after the data is posted.

Code: PHP

if($_SERVER['REQUEST_METHOD'] == 'GET')
    {
?>
    <form name=sub method=post>
    <input type=text name=ss>
    <input type=text name=cc>
    <input type=submit value=run>
    </form>
<?
    }
    else
    {
       
$ss=$_POST['ss'];
$cc=$_POST['cc'];
$array=array($ss,$cc);
?>
        <script language="JavaScript">
        function jss()
        {
        window.opener.document.add.cus.value="<?php echo base64_encode(serialize($array));?>";
        }
        jss();
        </script>

        <?
    }



All times are GMT +5.5. The time now is 05:02.