dmikester1 Posted October 21, 2007 Share Posted October 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/ Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 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'); Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374423 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 Cool, thanks. Now it seems like the ' (aposterphe's) are causing a problem. How do i correctly escape those? Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374431 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374435 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 I will certainly mark it. One more question for ya, how do I get access to that variable from the new page? Thank you Mike Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374445 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 The same way.. <?=$_GET['dir']?> -------- Since: dir=the_directory In that case, $_GET['dir'] would equal the_directory Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374450 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374459 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Nothing in your FORM has the name of dir... so $_GET['dir'] will equal nothing.. Im still lookin through your code though.. ill post again if i find another error.. but go ahead and fix this Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374463 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 Sorry for being such a noob here, but are you talking about my form in the popup window code? And what exactly do I need to give the name of "dir" to? Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374468 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 Change $_GET['dir'] to $_GET['filename'] Didnt you write that script? The form is the stuff you input Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374472 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 Well, it was a lot of copying from stuff I had found online because I don't know PHP enough. I'm trying to teach myself and it is slow going. Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374487 Share on other sites More sharing options...
Wes1890 Posted October 21, 2007 Share Posted October 21, 2007 ^ well did that work? Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374492 Share on other sites More sharing options...
dmikester1 Posted October 21, 2007 Author Share Posted October 21, 2007 Well I feel like an idiot, but I'm not totally sure on where you are talking about changing it. Chang this: $filedir = $_GET['dir']; to this: $filedir = $_GET['filename']; ? That didn't work for me. Quote Link to comment https://forums.phpfreaks.com/topic/74145-sending-variable-to-new-page/#findComment-374496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.