I’m loading an iframe up which will display text saying like “data submitted”. How do i get what comes up in the frame into a variable. For example.
$iframe = iframedata
Any help would be great.
Thanks
PS: Just donated £10 GBP to Cancer Research UK as a thank you for the continued support SitePoint users are giving me. Your help has not gone unnoticed.
To the the contents of an <iframe> all you need is the page URL and a cool PHP function called file_get_contents(). See the below example for a reference on how to accomplish this…
We submit data to one of our partners through an iframe, when we submit the data through their URL (e.g domain.com/submit.php?name=scott&email=scot@gmail.com) it will say text like “Data Added To Database”. What we need to do is grab that text and place it in a PHP Variable so we can add it do the database under the data we just submitted.
e.g:
iframe loads www.domain.com/submit.php?name=scott&email=scot@gmail.com
"Data Added To Database" is outputted on domain.com/submit.php?name=scott&email=scot@gmail.com
$iframecontent = "Data Added To Database"
You would need to have somebody on site b code their page to e-mail you, add to your database, or however you want the data. An iframe points somewhere else, so you would need to control the page you link to.
While sort of in a grey-area type of enviroment, you could generate the form on your own site, capture the data, and pass it on to the other site’s form. (Full disclosure would be morally required, naturally.)
We actually pass user registration data onto one of our clients which they pay us for, we just need to grab the output text when we pass the details onto them so we can see if the data was added to their database or not. Thats all I’m trying to do
Duplicate the other site’s HTML for the form, change the form handler to your own site. Catch the data yourself, do whatever you need to with it, and then use cURL to pass it to the client’s form handler. Client gets their data, but the browser stays on your website.
Duplicate the other site’s HTML for the form, leave the form handler as the client’s catcher. Add a javascript AJAX call to the form’s onsubmit to catch the data, and return true to send the browser to the client’s site with the data.
I assume that on submit that data is added to your database? If so, and they logically coded the form which lives on their site and you link to via iframe, the code should be like.
<?php
if( /*all data is valid*/ ){
// add to your database
// add to theirs
echo "data submitted";
} else { echo "retry";}