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

Discussion in 'PHP' started by rekha, Feb 28, 2008.

  1. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Can you some code snippet so that we have a better idea of how you are doing it??
     
  3. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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.
     
  5. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi pradeep

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



    Regards
    Rekha
     
  6. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Thi child page's code should look something like this, you need to call the JS function after the data is posted.

    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>

            <?
        }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice