nine72 Posted April 20, 2010 Share Posted April 20, 2010 Hey everyone...been awhile since I have been here but I have hit a roadblock that I cant seem to get past and I am sure that it is something simple. I have a form page that is more or less a user registration page. Collects: First Name Last Name Address .... From here I am posting to another page on my domain, but it calls an iFrame that loads from another domain. In my posting of the form data I am converting it to $_SESSION information and I need to pass that to this page from the other domain and I just cant figure it out... EXAMPLE: Form Page (only "hidden" because did not want to build all the fields to test) <form name="test" method="post" action="iframe_test.php"> <input type="submit" name="Submit"/> <input type="hidden" name="fName" value="ABC" /> <input type="hidden" name="lName" value="DEF" /> <input type="hidden" name="address1" value="GHI" /> <input type="hidden" name="address2" value="JKL" /> <input type="hidden" name="country" value="MNO" /> <input type="hidden" name="postal_code" value="PQR" /> <input type="hidden" name="city" value="STU" /> </form> From here the iframe_test.php page loads and I can do print_r ($_SESSION); and can see that the values have been passed to this page and the page loads the iframe just fine.. <body> <div align="center"><span class="style1"><strong>This is the iFrame Page</strong></span> </div> <div align="center"> <iframe src="http://other.domain.iframe.com" width="500" height="350" frameBorder="0"></iframe> </div> </body> I need to some how move the $_SESSION data to the http://other.domain.iframe.com domain. Mainly the reason for this is that it is a second registration at a partner site, and I am just trying to keep the user from having to re-enter their details....just trying to be user friendly a bit.....a bit. Any thoughts, suggestions, would be helpful....Oh and I have considered doing a urlencode but have not been able to make that work ither. Thanks! Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/ Share on other sites More sharing options...
cags Posted April 21, 2010 Share Posted April 21, 2010 The owner of the partner site would need to provide some form of API for you to set the values. I did wonder if you might be able to populate the form elements in an iFrame using JavaScript from the parent page, but I don't think the site will allow you access to the document object to allow you to do it. Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045831 Share on other sites More sharing options...
nine72 Posted April 21, 2010 Author Share Posted April 21, 2010 I have tried to use .js and converting the session information to a hidden from and do a "POST" to the iframe using an onLoad. This works but it breaks the iframe and loads the partner page directly. Wonder if I should find a js forum and see if there is some way to us js and hold the iframe inplace....or if it is possible to post the original form information to 2 urls. I was hoping that I could take the $_SESSION variables and encode them to the url that calls the iFrame and then decode them for that page in the iframe and use them that way....but I cant get that to work ether. (Granted I have never done encoding like that before so I may just be missing something... ) I think that this would be acceptable since none of the information being sent is sensitive... Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045842 Share on other sites More sharing options...
cags Posted April 21, 2010 Share Posted April 21, 2010 Did you set the target of the form to the id/name (I forget which) of the iFrame? Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045861 Share on other sites More sharing options...
nine72 Posted April 21, 2010 Author Share Posted April 21, 2010 Did you set the target of the form to the id/name (I forget which) of the iFrame? I am not sure exactally what you mean so bear with me... Do you mean that on the form from the first domain set it with a target id some thing like" <form name="test" method="post" target="partner" action="iframe_test.php"> and then set the iframe with <iframe src="http://other.domain.iframe.com" id="partner" width="500" height="350" frameBorder="0"></iframe> or something like that? Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045870 Share on other sites More sharing options...
cags Posted April 21, 2010 Share Posted April 21, 2010 Something along the lines of this... <?php if(isset($_POST['submit'])) { // do whatever your site wants with the information here // you might have to use a session variable to stop double submission } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Example</title> </head> <body> <form id="register" name="register" action=""> <input type="textbox" name="q"/> <input type="submit" name="submit"/> </form> <iframe id="partner_frame" name="partner_frame" src=""></iframe> <script type="text/javascript"> <?php if(isset($_POST['submit'])) : ?> var page_body = document.getElementsByTagName('body'); var partner_form = document.createElement('form'); partner_form.setAttribute('name', 'partner_form'); partner_form.setAttribute('action', 'http://www.google.com/search'); partner_form.setAttribute('target', 'partner_frame'); var username = document.createElement('input'); username.setAttribute('type', 'textbox'); username.setAttribute('name', 'q'); username.setAttribute('value', '<?php echo $_POST['q']; ?>'); partner_form.appendChild(username); page_body[0].appendChild(partner_form); document.forms['partner_form'].submit(); page_body[0].removeChild(partner_form); <?php endif; ?> </script> </body> </html> Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045947 Share on other sites More sharing options...
nine72 Posted April 21, 2010 Author Share Posted April 21, 2010 AHhhhhh, I will give this a shot and let you know how it rolls. Thank You cags! Link to comment https://forums.phpfreaks.com/topic/199193-session-data-passed-to-an-iframe-from-another-domain/#findComment-1045952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.