Reputation: 2790
I have a page containing an iframe and a form targeting the same page (outside the iframe). The form's output seems not to be visible within the iframe. The workaround I use now is that I take the $_POST form output outside the iframe, parse it to variables (with some default values if the form hasn't been sent yet) and then use the variables in the iframe definition. Then in the iframe I parse those values as $_GET. The iframe definition looks like this:
echo '<iframe src="foo.php?a='.$a.'&b='.$b.'" >';
Is this the optimal solution, or is there anything more elegant available through php?
EDIT: I tried to set form target to the iframe and action to the corresponding page, but doesn't seem to work; I'll try to inspect it further. I'm new to JavaScript and AJAX and elsewhere in my website I use very little JavaScript and no AJAX. I will inspect AJAX-using solutions, but I would prefer staying with php.
Upvotes: 0
Views: 785
Reputation: 1192
Does this help? using php sessions. it can be done in JavaScript as well, but since you seem to be affectionate about php, here it is. Inside "index.php"
<?php
session_start();
$_SESSION["name"] = isset($_GET['myName'])?$_GET['myName']:"";
?>
<form name="MyForm" action="" method="GET">
<input type="text" name="myName"/>
<input type="submit" />
</form>
<iframe src="iframe.php" name="myIframe"></iframe>
then within "iframe.php"
<?php
session_start();
echo $_SESSION["name"];
?>
Upvotes: 3