Forms & Frames: Passing form values to a window inside a frame


The following form passes information to show.php

               <form name="passthis" method="post" action="show.php">
               <input type=text name="content">
               <input type="submit">

show.php is something like this:

               echo "<html><body>". $_REQUEST['content'] ."</body></html>";

Now, I want to put show.php inside a frame.  In the following example, I want the information collected in the form to be displayed in the frame called "main2"

How can I pass the form values to a window inside of a frame?

         <frameset cols="*">
           <frameset rows="*,85%">
           <frame name="main" src="title.htm">
             <frameset cols="*,84%">
               <frame name="main1" frameborder=0 border=0 framespacing=0  src="menu.php" target="main">
               <frame name="main2" frameborder=0 border=0 framespacing=0  src="show.php" >

PS...   I hate frames! (but this project requires them)
LVL 16
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You should be able to do it using target="framename" in your form tag

eg: <form name="passthis" method="post" action="show.php" target="main2">
hankknightAuthor Commented:

The problem is that the first page (the one with the form in it) is not in the frame.  I want to open up a new window with the all of the frames in it, and show.php in the frame named "main2"
Off the top of my head im not sure if this is possible, thats not to say that its impossible but i certainly cant think of a method. The only alternative approach i can think of is to do this:

replace: <frame name="main2" frameborder=0 border=0 framespacing=0  src="show.php" >

with: <frame name="main2" frameborder=0 border=0 framespacing=0  src="show.php<?php echo "?content=".$_POST['content']; ?>" >

Then the show.php page can still use REQUEST to obtain the content value but using a "middle man" method.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Note: with the above the forms action would just be the frameset page without specifying a target.
hankknightAuthor Commented:
This is interesting.  

<frame name="main2" frameborder=0 border=0 framespacing=0  src="show.php<?php echo "?content=".$_POST['content']; ?>" >

I am passing 20K of information.  Would a "get" form method be able to handle this?
The get limit varies from browser to browser however the only reference on a limit i could find was for IE, a limit of 2,048 characters. Even so thats much less then what would be required for 20k and even so the query string isnt a great method for passing large amounts of data as it is which pretty much writes off that idea.

Leave this question open for awhile to see if anyone has a better idea, if i can think of a better method il post back.

You could optionally post a Q pointer in the HTML TA so someone can either confirm (or not) that its not possible to post to a specific frame from an external file.

ZvonkoSystems architectCommented:
The first expert comment did answer this question.
When the sending form has target set to a window name, then is the receiveng Response window any frame, iframe, popup or any sibling window which has either window name set by frame name, iframe name, pupup window name or simply set the window name by script.

So is the target="main2" really all you need.

Marcus BointonCommented:
You could pass all the params you need from the external frame by generating the form dynamically with a whole bunch of hidden fields to encode the passed data, depending on whether you need all the passed data immediately or are just passing it on. Otherwise it would be much more elegant to do all this through session variables as your frames could all access the big chunks of data without having to pass it around (unless your frames are coming from different servers, in which case you have security issues).
hankknightAuthor Commented:
session variables? how would this be done?
ZvonkoSystems architectCommented:
Why easy when you can get it complicated??? What for do you wnat to store the 20KB in Session variables?

You want simply to pass a field value from one form to another form.
All you need in show.php page is to repeat the posted value.

And that goes like this:

      <?php echo $_REQUEST["content"] ?>

If you want the data to repeat in a textarea, then use this:
<textarea name="content" rows="7" cols="80"><?php echo $_REQUEST["content"] ?></textarea>

If you want to display it in a <div>, then use this:
<div><?php echo $_REQUEST["content"] ?></div>

Where do you want to display the data in show.php?
Marcus BointonCommented:
> You want simply to pass a field value from one form to another form.

This is exactly why sessions were invented. It may be easy to do what you suggest for very few values, but as soon as you have more than that (the current multi-page form I'm working on has about 40), sessions provide a trivially simple solution, way easier than passing stuff manually, and it completely avoids the limits of GET.

Hank, all you need to do is add this at the start of your outer frame's script:


then place the submitted data that you want to pass into a session variable:

$_SESSION['myvar'] = htmlentities($_REQUEST['submittedvalue']);

then tell the frame to go wherever you want it to, and inside its script file, add the session_start, and then where you want to access the passed value, just do:

echo $_SESSION['myvar'];

and whatever you stored in there in your original frame script will magically reappear without you having to pass it between the two frames at all.

Once you start using sessions you'll wonder how you ever did without them.

The main place to avoid using sessions with multi-frame scripts is when the frames are hosted on different servers, when you start having lots of security concerns about sharing cookie values.

Incidentally, this:

<?php echo $_REQUEST["content"] ?>

is about as simple as you can make a script that's vulnerable to XSS (cross-site scripting) attacks, though it will of course also do what you said ;^)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hankknightAuthor Commented:
Thanks!   I am beginning to see the value of cookies.   And because this will only be used internally by administrators, I'm not worried about privacy issues or people having cookies turned off.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.