?
Solved

complete this code

Posted on 1999-12-10
5
Medium Priority
?
200 Views
Last Modified: 2010-03-05
i use the code below to let people
enter up to 20 words into seperate
text boxes but id like it to do this....

when i hit submit it will give me a x by y grid
with checkboxes for each row col intersection
so if i enter words like this
x1 "hi"
x2 "my"
x3 "name"
and then move down to y1
y1 "will
y2 "it"
y3 "work"
i will get the following grid when i hit submit
      hi my name
will  []   []    []
it     []    []   []
work  []  []   []

the [] represent unchecked check boxes....

there should also be a submit button at the end of this grid
and when a user checks all the check boxes they desire (and amount at all....in this example they can tick 0 to 9 check boxes)
the contents are put into a file "answers.txt"
like this


    hi    my    name
will x    x       x
it   o    o    o
work   o   o    o
(if the user checked the top three buttons)

hope its not too obscure
can someone repost my code so it will work like this
thanks
oh and please dont "answer" this question
i will accpt comments as answers!


use CGI qw(:standard);

                        print header,
                              start_html("simple submit");
                              print start_form,
                              "Enter X Value ",textfield('x1'),p,
                              "Enter X Value ",textfield('x2'),p,
                              "Enter X Value ",textfield('x3'),p,
                              "Enter X Value ",textfield('x4'),p,
                              "Enter X Value ",textfield('x5'),p,
                              "Enter X Value ",textfield('x6'),p,
                              "Enter X Value ",textfield('x7'),p,
                              "Enter X Value ",textfield('x8'),p,
                              "Enter X Value ",textfield('x9'),p,
                              "Enter X Value ",textfield('x10'),p,
                              "Enter Y Value ",textfield('y1'),p,
                              "Enter Y Value ",textfield('y2'),p,
                              "Enter Y Value ",textfield('y3'),p,
                              "Enter Y Value ",textfield('y4'),p,
                              "Enter Y Value ",textfield('y5'),p,
                              "Enter Y Value ",textfield('y6'),p,
                              "Enter Y Value ",textfield('y7'),p,
                              "Enter Y Value ",textfield('y8'),p,
                              "Enter Y Value ",textfield('y9'),p,
                              "Enter Y Value ",textfield('y10'),p,
                              submit,
                              end_form;

print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
print "param('x1')";
                        print end_html;
0
Comment
Question by:boofulls
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:Mindo
ID: 2273803
Here's my answer to your question (i didn't post it as an answer as you asked me).

The script file (matrix.cgi) that displays edit boxes:
========================================
#!/usr/local/bin/perl

use CGI qw(:standard);

$q = new CGI;

print $q->header,
      $q->start_html("Form Demo"),
      $q->h1("Form Demo");

$length = 10;
$max = 10;
$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matr.cgi";
print $q->startform($method, $action, "");

foreach $i(1..10)
{
  $name = "X".$i;
  print "Enter X Value ";
  print $q->textfield($name, $value, $length, $max);
  print "<br>";
}

print "<br>";

foreach $i(1..10)
{
  $name = "Y".$i;
  print "Enter Y Value ";
  print $q->textfield($name, $value, $length, $max);
  print "<br>";
}

print "<br>";
print $q->submit;
print $q->reset;
print "<br>";

print $q->endform;
print $q->end_html;
========================================

The file(matr.cgi) that receives results from the matrix.cgi file and displays a matrix of checkboxes.
========================================
#!/usr/local/bin/perl -w

use CGI qw(:standard);

$q = new CGI;

@x = ();
@y = ();

foreach $i(1..10)
{
  push(@x, param("X".$i))
}

foreach $i(1..10)
{
  push(@y, param("Y".$i))
}

print $q->header,
      $q->start_html("Form Results"),
      $q->h1("Form Results");

$method = "POST";
$value = "";
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";      
print $q->startform($method, $action, "");

print "<br>";

foreach $i(1..10)
{
  print "| $x[$i-1] |\n";
}
print "<br>";
 
foreach $i(1..10)
{
  print "| $y[$i-1] |\n";
  foreach $j(1..10)
  {
    print $q->checkbox_group(-name=>"g".$i.$j,
                           -values=>["n".$i.$j]);
  }
  print "<br>";
}

print "<br>";
print $q->submit;
print $q->reset;
print "<br>";

print $q->endform;
print $q->end_html;
========================================

The file (matrres.cgi), which prints the results received from the matr.cgi file. Also, it prints results to the file as you requested.

========================================
#!/usr/local/bin/perl -w

use CGI qw(:standard);

$q = new CGI;

print $q->header,
      $q->start_html("Form Results"),
      $q->h1("Form Results");

open(F, "> results.txt");
foreach $i(1..10)      
{
  foreach $j(1..10)
  {
    @i = param("g".$i.$j);
    if(length($i[0]) > 0)
    {
      print F "$i[0]\n";      
      print "$i[0]\n";      
      print "<br>";
    }
  }
}
print $q->end_html;
close(F)
========================================

I didn't worked on the alignment of the checkboxes. It's left for the HTML gurus :-)

You can take a look at how it works on my site at:

http://www.soften.ktu.lt/~genumind/perl/matrix.cgi

Cheers
0
 

Author Comment

by:boofulls
ID: 2276571
this doesnt seem to work the way id like but i thank you very much for your help
say i enter
x1 x2 x3 and y1 y2 y3
for the first 3 x and y values respectively then i should only get a 3 by 3 grid but this gives me a 10 by 10 grid!
0
 
LVL 2

Expert Comment

by:Mindo
ID: 2276639
Hehe, i thought you could do it for yourself :-)

To manage the number of checkboxes you just have to check the length of the parameter. Here's the source code of the second script with 3 "if" statements added:

========================================
#!/usr/local/bin/perl -w
                 
use CGI qw(:standard);                
                 
$q = new CGI;                
                 
@x = ();                
@y = ();                
                 
foreach $i(1..10)                
{                
  push(@x, param("X".$i))                
}                
                 
foreach $i(1..10)                
{                
  push(@y, param("Y".$i))                
}                
                 
print $q->header,                
      $q->start_html("Form Results"),                
      $q->h1("Form Results");                
                 
$method = "POST";                
$value = "";                
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";                
print $q->startform($method, $action, "");

print "<br>";

foreach $i(1..10)
{
  if(length($x[$i-1]) > 0) # The X Column.
  {
    print "| $x[$i-1] |\n";
  }
}
print "<br>";
 
foreach $i(1..10)
{
  if(length($y[$i-1]) > 0)# The Y Column.
  {
    print "| $y[$i-1] |\n";
    foreach $j(1..10)
    {
      if(length($x[$j-1]) > 0)# The X Column.
      {
        print $q->checkbox_group(-name=>"g".$i.$j,
                           -values=>["n".$i.$j]);
      }
    }
    print "<br>";
  }
}

print "<br>";
print $q->submit;
print $q->reset;
print "<br>";

print $q->endform;
print $q->end_html;
========================================
I wrote you the core. Add simple changes for yourself. Do you want experts here to write all of your software? :-)
0
 

Author Comment

by:boofulls
ID: 2276719
ok thats cool
i did that and it works thanks

just one last thing
instead of writing
n11
n12
n13 to the results file if i click the top three boxes
is it possible to write

hi my name
will it work
11 12 13
into the file
ie all the x values on the first line (each seperated by a tab )
all the y values on the second line (each sperated by a tab)
and then all the checked boxes seperated by a space

thanks
(i also have a follow up question....
ill post it here and add another 200 points.....
its easier that this.....)
0
 
LVL 2

Accepted Solution

by:
Mindo earned 1000 total points
ID: 2276783
Did it. The second script writes the x and y values, since it gets them from the first script. The third script writes the checkbox values like 11 12 13. Everything is written to the file results.txt by appending data to it.

The modified second script:
========================================
#!/usr/local/bin/perl -w
                 
use CGI qw(:standard);                
                 
$q = new CGI;                

open(F, ">> results.txt");                

@x = ();                
@y = ();                
                 
foreach $i(1..10)                
{                
  push(@x, param("X".$i))                
}                
                 
foreach $i(1..10)                
{                
  push(@y, param("Y".$i))                
}                
                 
print $q->header,                
      $q->start_html("Form Results"),                
      $q->h1("Form Results");                
                 
$method = "POST";                
$value = "";                
$action = "http://www.soften.ktu.lt/~genumind/perl/matrres.cgi";                
print $q->startform($method, $action, "");

print "<br>";

foreach $i(1..10)
{
  if(length($x[$i-1]) > 0)
  {
    print "| $x[$i-1] |\n";
    print F "$x[$i-1]\t";
  }
}
print "<br>";
 
print F "\n";

foreach $i(1..10)
{
  if(length($y[$i-1]) > 0)
  {
    print "| $y[$i-1] |\n";
    print F "$y[$i-1]\t";
    foreach $j(1..10)
    {
      if(length($x[$j-1]) > 0)
      {
        print $q->checkbox_group(-name=>"g".$i.$j,
                           -values=>[$i.$j]);
      }
    }
    print "<br>";
  }
}

print "<br>";
print $q->submit;
print $q->reset;
print "<br>";

print $q->endform;
print $q->end_html;

print F "\n";
close(F);
========================================

The modified third script:
========================================
#!/usr/local/bin/perl -w

use CGI qw(:standard);

$q = new CGI;

print $q->header,
      $q->start_html("Form Results"),
      $q->h1("Form Results");

open(F, ">> results.txt");
foreach $i(1..10)      
{
  foreach $j(1..10)
  {
    @i = param("g".$i.$j);
    if(length($i[0]) > 0)
    {
      print F "$i[0] ";      
      print "$i[0]\n";      
      print "<br>";
    }
  }
}
print $q->end_html;
print F "\n";      
close(F);

========================================
Here the sample results.txt file:
========================================
XOne    XTwo    XThree  XFive
YOne    YTwo    YThree  YFive
11 12 13 32 33 53 55  
========================================
Hope you'll find the places where i print to the file handle "F" :-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

593 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