Passing variables to frames

Discussion in 'Perl Misc' started by divya, Feb 24, 2005.

  1. divya

    divya Guest

    This is the problem I am having:
    I have an index page where I obtain input from the user (for example
    their date of birth). This information is passed to Page2. Page2 has
    frames. Outside of the frames I can access the user's input. But within
    the frames I can't seem to be able to get the value. The date is stored
    in a global variable.
    Here are snippet's of code:

    ##Variables
    my ($BDAY, $path_info, $script_name);

    ##Obtaining value from the index page
    if ($q->param('birthday')) {
    $BDAY = $q->param('birthday');
    }

    ##Creating frame
    $path_info = $q->path_info;

    ##Printing the fames
    if (!$path_info) {
    &print_frameset($BDAY);
    exit 0;
    }

    ##Printing the different frames
    &print_html_header; ##HTML headers
    &print_content if $path_info=~/content/; ##Left pane with links
    &print_expand($BDAY) if $path_info=~/expand/; ##Expanded graph
    &print_analyse if $path_info=~/analyse/; ##Options to do
    analysis
    &print_end; ##End HTML
    &print_error;

    ##Setting up the frames
    sub print_frameset {

    my $birthday = shift;
    $script_name = $q->script_name;

    print "<html><head><title>$TITLE</title></head>";
    print "<frameset cols='8%,92%'>";
    print "<frame src='$script_name/content' name='content'>";
    print "<frameset rows='70%,30%'>";
    if ($birthday) {
    print "<frame src='$script_name/expand' name='expand'>";
    print "<frame src='$script_name/analyse' name='analyse'>";
    }
    else {
    print "<frame src='$script_name/error' name='error'>";
    }
    print "</frameset>";
    print "</frameset>";

    exit 0;
    }

    One of the frame's contents:
    sub print_expand {

    my $birthday = shift;
    print $q->h3("My birthday is on: $birthday");

    }

    In this frame all it prints is "My birthday is on: " it is not printing
    the variable.

    I cannot figure out why I cannot get the value in the subroutines. I
    have checked and the value does get passed from the index page to this
    page. I can print it from the global variable $BDAY but not from the
    sub routines that form the frames.

    I have spent almost 2 days on this and I am starting to go insane!! I
    would appreciate any hints/help/suggestions you can provide.

    Thanks!
    Me
    divya, Feb 24, 2005
    #1
    1. Advertising

  2. "divya" <> wrote in news:1109216654.641937.174730
    @z14g2000cwz.googlegroups.com:

    > This is the problem I am having:
    > I have an index page where I obtain input from the user (for example
    > their date of birth). This information is passed to Page2. Page2 has
    > frames. Outside of the frames I can access the user's input. But
    > within the frames I can't seem to be able to get the value.


    You do not have a Perl question. You just do not know HTML & CGI. You
    should direct HTML queries to

    comp.infosystems.www.authoring.html

    and CGI queries to

    comp.infosystems.www.authoring.cgi

    > my ($BDAY, $path_info, $script_name);


    Declare variables in the smallest applicable scope.

    > ##Obtaining value from the index page
    > if ($q->param('birthday')) {


    $q is not defined at this point.

    use strict;
    use warnings;

    would have told you that.

    > $BDAY = $q->param('birthday');
    > }
    >
    > ##Creating frame
    > $path_info = $q->path_info;
    >
    > ##Printing the fames
    > if (!$path_info) {
    > &print_frameset($BDAY);


    Do you know the difference between

    &print_frameset($BDAY)

    and

    print_frameset($BDAY)?

    If you do not need the specific effects of using &print_frameset, then
    you should not use it. See

    perldoc perlsub

    for more information.

    Sinan
    A. Sinan Unur, Feb 24, 2005
    #2
    1. Advertising

  3. divya wrote:
    > This is the problem I am having:
    > I have an index page where I obtain input from the user (for example
    > their date of birth). This information is passed to Page2. Page2 has
    > frames. Outside of the frames I can access the user's input. But within
    > the frames I can't seem to be able to get the value.


    Do you realize that the script is called multiple times? The first time
    it only prints the frameset file.

    > print "<frame src='$script_name/content' name='content'>";


    Here the script is called a second time from the frameset file, and as
    far as I can see, no parameters are passed to it that time...

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 24, 2005
    #3
  4. "A. Sinan Unur" <> wrote in
    news:Xns9606EACCF4560asu1cornelledu@127.0.0.1:

    > "divya" <> wrote in news:1109216654.641937.174730
    > @z14g2000cwz.googlegroups.com:
    >
    >> This is the problem I am having:
    >> I have an index page where I obtain input from the user (for example
    >> their date of birth). This information is passed to Page2. Page2 has
    >> frames. Outside of the frames I can access the user's input. But
    >> within the frames I can't seem to be able to get the value.

    >
    > You do not have a Perl question. You just do not know HTML & CGI.


    Well, I just re-read this, and realized that it comes accross harsher
    than I had intended. What you have is:

    > print "<frame src='$script_name/expand' name='expand'>";
    > print "<frame src='$script_name/analyse'

    name='analyse'>";

    These will result in two fresh invocations of your script without the
    birthday parameter.

    See

    <URL: http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#CREATING_A_SELF-
    REFERENCING_URL_THAT_PRESERVES_STATE_INFORMATION:>

    and

    <URL: http://search.cpan.org/~lds/CGI.pm-
    3.05/CGI.pm#WORKING_WITH_FRAMES>

    for more information.

    Sinan.
    A. Sinan Unur, Feb 24, 2005
    #4
  5. A. Sinan Unur wrote:
    >
    > <URL: http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#CREATING_A_SELF-REFERENCING_URL_THAT_PRESERVES_STATE_INFORMATION:>


    It should be noted that CGI.pm's self_url() method translates all
    parameters, whether submitted via POST or GET, to a query string. If
    there initially were info passed to the script, that you wouldn't like
    that the server sends to the user and saves in the access log, it may be
    advisable to add the necessary query string manually. In this case it
    seems to be:

    my $querystring = "?birthday=$BDAY";

    (The need for URI escaping should better be considered, of course.)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. divya
    Replies:
    1
    Views:
    616
    Joe Smith
    Feb 24, 2005
  2. Powerslave2112

    From Frames to no frames?

    Powerslave2112, Jan 20, 2004, in forum: HTML
    Replies:
    2
    Views:
    567
    brucie
    Jan 20, 2004
  3. Philip
    Replies:
    3
    Views:
    945
    Karl Groves
    Jun 28, 2004
  4. Ale

    Frames or not Frames...

    Ale, Aug 3, 2005, in forum: HTML
    Replies:
    17
    Views:
    937
    Adrienne
    Aug 5, 2005
  5. A Web Master
    Replies:
    4
    Views:
    215
    A. Webmaster
    Jan 28, 2004
Loading...

Share This Page