Solved

CGI beginner - why no refresh?

Posted on 2002-07-03
8
362 Views
Last Modified: 2013-12-25
I think I may under a misapprehension as to what CGI is all about.
I have debugged and debugged my perl software down to a point wherby it is a simple item that is going wrong. (The bones of the code are below)

Why does this code not give me "Fred" in my text area? I know that the correct path is being followed when I press the button as the printing of the string "$MyString" at the end of the code gives me the correct printout - it just doesn't refresh my text area.

I was under the apprehension that if I send a whole new web page, this would replace what was on the screen but it doesn't seem to.
What am I missing when it comes to CGI?
How do I refresh what is on my screen?

Many thanks from a CGI beginner.

use CGI;
$co = new CGI;

if ( ! $co->param())
{
  $MyString = "Hello";
  DrawPage();
}
else
{
  if ($co->param('MyButton') ne "")
  {
    HandleRequest();
    DrawPage();
  }
}

sub HandleRequest
{
  $MyString="Fred";
}

sub DrawPage
{
  print
        $co->header(),
      $co->start_html
      (
      ),
      $co->start_form(),

          $co->textarea
          (
            -readonly=>'true',
            -name=>'MyArea',
            -default=>$MyString,
            -rows=>10,
            -columns=>45
          ),
           $co->submit
            (
              -name=>'MyButton',
              -value=>'Button'
            ),
      $co->end_form,
      "$MyString",
      $co->end_html;
 }
0
Comment
Question by:GSD4ME
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:samri
ID: 7129472
Strange too.

Added $MyString in the title, it appears to be Fred.
     $co->start_html
     (-title=>$MyString
     ),

Somehow, it the textbox, it's Hello again.

If we change the $co->param(-name->MyArea,-value=Fred), then it works.

-- modified sub.
sub HandleRequest
{
 $MyString="Fred";
 $co->param(-name=>MyArea,value=>Another);
}

I still can't explain what is happening.  I would have suspected that the Assignment is not happening, but the title page show the Fred.  
0
 
LVL 15

Expert Comment

by:samri
ID: 7129476
Much cleaner way, also work.

sub HandleRequest
{
 $MyString="Fred";
 $co->param(-name=>MyArea,value=>$MyString);
}
0
 
LVL 2

Accepted Solution

by:
VEngineer earned 50 total points
ID: 7132711
I found a solution, but not a root cause.  To solve this problem, you need to add one more parameter into your textarea function call:

$co->textarea
     (
     -readonly=>'true',
     -name=>'MyArea',
     -default=>$MyString,
     -rows=>10,
     -columns=>45,
     -override=>1
     ),


This is where I read about it:
http://stein.cshl.org/WWW/CGI/#overriding

It's *not* something that shows up in the HTML source for some reason.  I'm not exactly sure what's happening behind the scenes, but if I find out, I'll pass word along.  Another tip from a former beginner -- use strict; in every script you write and explicitly declare every variable you use.  It will save you countless headaches.  Here's how I'd write your script:

use strict;
use CGI;
use CGI::Pretty;

# CGI::Pretty makes the HTML source readable for debugging

my $co = new CGI;

my $MyString = "";

if (! $co->param()) {
      $MyString = "Hello";
      DrawPage();
}
elsif ($co->param('MyButton') ne "") {
      HandleRequest();
      DrawPage();
}


sub HandleRequest {
      $MyString = "Fred";
}

sub DrawPage {
      print $co->header(),
         $co->start_html(),
         $co->start_form(),

         $co->textarea(
              -readonly=>'true',
              -name=>'MyArea',
              -default=>$MyString,
              -rows=>10,
              -columns=>45
              -override=>1),

         $co->submit(-name=>'MyButton', -value=>'Button'),
         $co->end_form(),
         $co->end_html;
}
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 12

Expert Comment

by:lexxwern
ID: 7133503
the pont is most cgi programmers rely too mch on the CGI module, if you are familiar with html, why not do it direct like this..


#!/usr/bin/perl -w

print "Content-type: text/html\n\n";

print qq(
<input type="text" value="fred, john and mary"/>
);

0
 
LVL 15

Expert Comment

by:samri
ID: 7133719
lexxwern,

off topic:  I have the same thought before.  Now started to learn CGI.pm.  Personally, which do you prefer; "homemade" modules (ala CGI.pm), or the CGI.pm that comes with perl.

gsd4me: sorry to *hijack* your thread for a while. :)

cheers.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7133775
<offtopic>
me having good expertise in html, dont use any modules, it gives me the "html freedom" that i like :)
so i cant comment on this, sorry.
</offtopic>
0
 

Author Comment

by:GSD4ME
ID: 7142813
VEngineer
you're a star!
The fix works and everything is now hunky-dory!

Before I close this question, one little point please.

The form that this whole question relates to accesses its
own data files under my cgi-bin directory.
No-one else (apart from me uploading and downloading those data files) can see the data files.
What permissions do I need to set on the data files?
DO I need to give NO access to everyone else except the owner?
Lots of people will be accessing the data files (via the program) and they will require to read from and write data to the files which is only done VIA THE PROGRAM.
Does this affect the access permissions?
0
 

Author Comment

by:GSD4ME
ID: 11293053
Just clocing this question - beebn open for far too long
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Auto-indent certain lines in Notepad++ 10 173
powershell switch statement 7 47
Move files based on file names? 8 68
msiexec won't run 4 31
In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question