Jump to content

Recommended Posts

I am popping up a new window with Javascript and I need to send a PHP variable to that new window.  I think this is the way I need to do that.  But I get a JS error that $_GET is not defined.

 

win = window.open('MikesFileEditor.php?dir='+$_GET['dir'],'window','height=750, width=700,toolbar=no,directories=no, status=no, menubar=no,scrollbars=no,resizable=no');

 

Any help would be appreciated.  Thanks!

Mike

Link to comment
https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/
Share on other sites

Thats because JS and PHP can't talk to each other... UNLESS

 

use php to echo your javascript stuff

 

<?php
echo "win = window.open('MikesFileEditor.php?dir='".$_GET['dir']."','window','height=750, width=700,toolbar=no,directories=no, status=no, menubar=no,scrollbars=no,resizable=no');";
?>

 

Or, just replace what you had, with this.. I added the <?=$_GET['dir']?>

 

win = window.open('MikesFileEditor.php?dir='<?=$_GET['dir']?>','window','height=750, width=700,toolbar=no,directories=no, status=no, menubar=no,scrollbars=no,resizable=no');

Change it to this.. all i did was take them out :)

 

win = window.open('MikesFileEditor.php?dir=<?=$_GET['dir']?>,'window','height=750, width=700,toolbar=no,directories=no, status=no, menubar=no,scrollbars=no,resizable=no');

 

 

be sure to mark this topic as SOLVED when you're done :)

OK, I am getting so frustrated with this.  I echo out the current working directory before I save the file and it is correct.  Once I hit "save" it switches back to the home dir and saves the file there.  Here is my code for the popup window:

 

<? echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>Simple File Editor</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script type="text/javascript">
//<![CDATA[
<!--
function checkIfEmpty(filename) {
var result = true;
var message = "";
if(filename == "") {
message = "Please type a name for the file(including extension)";
popupText(message);
result = false;
}
else {
message = filename;
popupText(result);
}
return result;
}

function popupText(message) {
document.getElementById('hidden').innerHTML = message;
document.getElementById('hidden').style.display = "block";
}

-->
//]]>
</script>
</head>
<body>
<div>
<?php
$filedir = $_GET['dir'];
//echo "filedir is: $filedir";

if($filedir == "")
{
  $filedir = ".";
}





if(is_readable($filedir)) //check that the get "value" is readable
{
chdir($filedir);
$cwd = getcwd()."/";
echo getcwd();
?>
</div>
<h1>Currently in <span class="red"><?php echo $cwd; ?></span></h1>
<form method="POST"  action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="center">
<textarea rows="30" cols="80" style="border: 1px solid #666666;" name="updatedfile">
</textarea></div>



<div class="center">Name of file: <input type="text" name="filename" id="filename" /><br /><div id="hidden"></div>
<input type="submit" name="save" id="save" value="Save Changes" /> <!-- onclick="return checkIfEmpty(document.getElementById('filename').value)" /> -->
<?php
if (isset($_POST['save']))
{  //if the "save" button was clicked
	$file = $_POST['filename'];
	$file = $cwd.$file;
	echo "da file: .$file";
	$file2save = fopen($file, "w+");
	if (is_writable($file))
	{
		$data_to_save = $_POST["updatedfile"];
		$data_to_save = eregi_replace("<END-TA-DO-NOT-EDIT>", "</textarea>", $data_to_save);


		if (fwrite($file2save,$data_to_save))
		{
			//echo "<meta http-equiv='refresh' content='0;URL=MikesFileEditor.php'>";
			echo "file saved!";
			//Close file
			//fclose($file2save);
		}else {
			//If write fails show failure page
			echo "file not saved!";
			//Close file
			fclose($file2save);
		}

	}else {
		echo "not writable!";
	}
	fclose($file2save);
}
}
?>
</div>
</form>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.