Member Avatar for Lioshenka

I have two pages, both extremely simple. One of the has some code on it which is literally an iframe with some basic CMS controls which allows the user to enter some text in it (by default it reads some pre-written text from a file and pastes it into the iframe).

<?php
session_start();
if (isset($_SESSION['logged_in']) != true) {
    header('Location: login.php?ermess=logout');
}
echo "<?xml version='1.0' encoding='UTF-8'?>";

$_SESSION['pagename'] = $_GET['pagename'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <link rel="stylesheet" type="text/css" href="cpanel.css" />

    <head>

        <title>Page editor</title>
        <script type="Javascript" src="editor.js"></script>
    </head>
    <body>
        <form method="POST" action="saver.php">
            <div>
                <input type="button" onclick="Colour('Green')" style="background-color:Green;" />
                <input type="button" onclick="Colour('Red')" style="background-color:Red;" />
                <input type="button" onclick="Colour('Blue')" style="background-color:Blue;" />
                <input type="button" onclick="Colour('Black')" style="background-color:Black;" />
                <input type="button" onclick="Format('bold')" value="B" />
                <input type="button" onclick="Format('italic')" value="I" />
                <input type="button" onclick="Format('Underline')" value="U" />
                <input type="button" onclick="Format('justifycenter')" value="C" />
                <input type="button" onclick="Format('justifyleft')" value="L" />
                <input type="button" onclick="Format('justifyright')" value="R" /><br/>

<?php echo "<iframe id='textbox' name='textbox' style='width:300px; height:150px'; src='../site/{$_GET['pagename']}'></iframe><br/>"; ?>


                <input type="submit" value="Save changes" />
                <input type="hidden" id="text" name="text" />

            </div>
        </form>
    </body>
</html>

Then the user clicks Save, and the text from an iframe gets POSTed to another page, which is suposed to echo it, but doesn't.

<?php session_start();
if (isset($_SESSION['logged_in']) != true) {
    header('Location: login.php?ermess=logout');
}
echo "lol";
echo $_POST['text'];
echo $_POST['textbox'];

?>

So - iframe, submit button, echo.

I went over and over the code and can't see why the text doesn't get posted... Any help would be greatly appreciated!

Recommended Answers

All 2 Replies

The <iframe> is not a form element so you will not be able to transfer data from an Iframe through a $_POST or $_GET via the url. You will most probably have to use a <textarea> which is a form element in order to transfer data.

If you have to use a text box and transfer the code from the <iframe> to the textbox using Javascript using which you can then send the data through the POST.

Try this code.

<html>
<head>
<title>Shopping cart test</title>
<script>
function tryout(){
	x=window.frames["txtbox"].document.documentElement.outerHTML;
	document.getElementById("code").value=encodeURI(x);	
}
</script>
</head>
<body>
<form onsubmit="tryout()" action="#" method="post">
<iframe name="txtbox" id="txtbox" src="check_links.php">hi</iframe><br />
<input type="text" name="code" id="code" /> 
<input type="button" onclick="tryout()" value="Click" />
<input type="submit">
</form>
</body>
</html>

You can access the urldecode($_POST['code']) to get the code from the iframe.

All the best!!!

commented: Thanks for your help with PHP/JS +4
Member Avatar for Lioshenka

That's it, brilliant! Thank-you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.