Page 1 of 1

cookies? or no?

Posted: Tue Dec 05, 2006 10:19 pm
by cmazur
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey guys (and girls),

I'm having trouble accessing data from an old window in a new window.
Let me re-phrase this... 
The user of my site needs to click an 'open' button on the page to open a data record. The button opens the record in a new window. This is where the problem is, I need to get the information off of the initial page and use it in the new window. 

I've tried cookies, and that is not working.. here is what i did when i tried using cookies, maybe it's something simple that i'm not doing right (i'm new to this whole web programming thing)...


This is when i set the cookie...

Code: Select all

<form id="form1" name="form1" method="post" action="log.php">
		<p><h2>Notes</h2>
			<select name="notes" size="5" id="notes">
			<?php fill_notes($id); ?>
			</select><br />
			<input name="add_note" type="submit" id="add_note" value="Add" />
			<textarea rows="2" name="add_note_text" cols="50"></textarea>
			<br />
			<input name="edit_note" type="submit" id="edit_note" value="Edit" />
			<textarea rows="2" name="edit_note_text" cols="50"></textarea>
			<br />
			<input name="delete_note" type="submit" id="delete_note" value="Delete" />
			<br />
			<input name="open_note" type="button" id="open_note" value="Open" onclick=
				<?php setcookie("message", $_POST["notes"], time() + 86400); ?>"open_notes()" />
			</p>
This is where i open the new window...

Code: Select all


<head>
	<title>Note-Taker</title>
	<script type="text/javascript">
	<!--
		// Function:		open_notes()
		// Parameters:	none
		// Returns:		none
		// Description:	opens a note in the user's list in a full popup window
		function open_notes()
		{
			//Get the message
			var message = document.getElementById("notes").value;
	
			//Open the note in a new simple popup window
			window.open("message.php", "winlink", "height=400, width=800");
		}
	//-->
	</script>
</head>

And this is where I try to get the data in the cookie in the new window...

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Message Viewer</title>
</head>

<body>
	<?php
		if(isset($_COOKIE["message"]))
		{
			$message = $_COOKIE["message"];
			echo '$message';
		}
		else
		{
			print("Sorry, an error has occured...");        //THIS ALWAYS PRINTS...
		}
	?>
</body>
</html>
Any insight would be greatly appreciated.
If you need more background info, just let me know..

Thanks again!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Dec 05, 2006 10:38 pm
by Burrito
you could use javascript and access any form elements on the parent page with the 'opener' object on the pop up page.

ex:

Code: Select all

<script>
document.someForm.someField.value = opener.document.someForm.someField.value;
</script>

Posted: Tue Dec 05, 2006 11:40 pm
by cmazur
thanks, look like that will help...