• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

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

Hello.

The following form passes information to show.php

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


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?


         <html>
         <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" >
             </frameset>
           </frameset>
          </frameset>
         </html>


PS...   I hate frames! (but this project requires them)
0
hankknight
Asked:
hankknight
  • 4
  • 4
  • 2
  • +1
1 Solution
 
Diablo84Commented:
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">
0
 
hankknightAuthor Commented:
Thanks!

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"
0
 
Diablo84Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Diablo84Commented:
Note: with the above the forms action would just be the frameset page without specifying a target.
0
 
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?
0
 
Diablo84Commented:
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. http://support.microsoft.com/kb/q208427/ 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.

0
 
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.

0
 
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).
0
 
hankknightAuthor Commented:
session variables? how would this be done?
0
 
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?
0
 
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:

session_start();

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 ;^)
0
 
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now