Forum Moderators: coopster

Message Too Old, No Replies

Putting the result of a form into an iframe on the target page

grab results using POST and put them into an iframe

         

proper_bo

10:50 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



I have had a good look for this both on this forum and over the www. Can't seem to find what I want, although I am sure it has been asked before:

I have a form on a page....lets call it one.php
This forms target it the same page one.php

I know how to make an iframe appear when the form has been submited with certain characteristics, but how do I get the reults of the form to appear in the iframe.

Im trying to make it simple to highlight the form results and I am aware there is a piece javascript that can highlight iframe content.

Does the iframe contents have to be a seperate page?

Is there a good way to make a second page with the results? Can it just be:


<?php
echo $_POST['formpart'];
?>

or because it is in an iframe with this not work?
Thank you

ps. this is a new user name for a not-so-new user, I am however always grateful to all who help here.

carneddau

11:40 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Hi,

Is there a reason why the results have to appear in an iframe? Can't you just display the results of the form on the page or in a pop-up?

One way to do this would be to create a temp file and drop the html you want to display in it and point the iFrame to it. Haven't tried it but in theory it should work.

Cool name by the way, "can i get a rewind"

proper_bo

11:48 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



Hi there, cheers for the help.

The only reason I was considering an iframe is the javascript highlighter I mentioned. Saves three clicks or a click and drag.

Can you explain the temp file a little further.

Thank you

carneddau

12:06 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Okay, I'll give it a go.

-------------------------------------------
<?php
$page = fopen("results.html", "w");
$page_content = "<html><head><title>Results</title></head><body>";
$page_content .= "<b>Proper Bo I tell thee</b>";//this is where you dump the results
$page_content .= "</body></html>";
fwrite($page, $page_content);
fclose($page);
?>
<html>
<head></head>
<body>
<iframe src="results.html" title="results">
<!-- alternate content for non-supporting browsers -->
</iframe>
</body>
</html>
-------------------------------------------

That basically does what you're after but you'll need a way of making random results filenames and "cleaning up" the results files when they are no longer needed.

proper_bo

9:30 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Ok, nice. I see where your going now.

So everytime a form is submited a new .html is created with a new name and the content of the form which then appears in the iframe.

I could make the new pages random quite simply by creating a random number and calling it $newpage and then
doing something like this:
-------------------------------------------
randomnumber (not actually creating here) = $newpage

$page = fopen($newpage . ".html", "w");
$page_content = "<html><head><title>Results</title></head><body>";
$page_content .= "<b>Proper Bo I tell thee</b>";//this is where you dump the results
$page_content .= "</body></html>";
fwrite($page, $page_content);
fclose($page);
?>
<html>
<head></head>
<body>
<iframe src="<?php $newpage?>.html" title="results">
<!-- alternate content for non-supporting browsers -->
</iframe>
</body>
</html>
-------------------------------------------

correct?
I could use a folder just for the temps and empty is every now and again, the files will only be small.

Anyone have a better/simpler way of doing this?

carneddau

11:58 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Hi,

Yes, in theory that will do it.

I reckon this is quite a poor solution to the problem though. A better solution would be to call a php script from the iframe, the problem is getting the posted values to that script :¦

Anyone else have any ideas here?

mykel79

7:36 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



Here's an idea.
Two scripts - form.php and iframe.php
form.php contains the form - let's say it has two fields, who's values get stored in $field1 and $field2 after you submit the form.
When you submit, an iframe is made something like this:
echo '<iframe src="iframe.php?val1=',$_POST['field1'],'&val2=',$_POST['field2'],'">';

The file iframe.php can now print out the parameters it has sent to it.
echo $_GET['val1'];
echo $_GET['val2'];

carneddau

8:43 pm on Mar 9, 2004 (gmt 0)

10+ Year Member



Good thinking mykel79, I didn't think it was possible to do this. This is a much better solution than the above.

proper_bo

9:46 am on Mar 10, 2004 (gmt 0)

10+ Year Member



Excellent. I'll try that and get back to you on how it goes.

Why didn't I think of that o_O.

Thank you.