[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

"Add" button to add additional forms for submission (reusable component?)

Posted on 2003-10-24
6
Medium Priority
?
196 Views
Last Modified: 2013-12-25
Greetings!

I have to customize yform.cgi, to allow for multiple requests of bottle collections.  Right now, it is statically set for 18 different bottle collections (there are 18 identical forms hardcoded in my script).  However, I'd like for the form to display only one form for bottle collection, by default, and have a button, entitled "Add Form", which will return a new form  for bottle collection, every time this button is pushed, so that anywhere from '1n' to 'n-1' forms will be generated at the push of this button.  I'm assuming I have to have a function with the form, and have it called every time the button "Add Form" is pushed .. but I'm really fuzzy about the implementation.  Can anyone please help me out?

Thanks!!
Janice  
0
Comment
Question by:jmc430
[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
  • 4
  • 2
6 Comments
 
LVL 8

Expert Comment

by:inq123
ID: 9618053
Hi jmc430,

Just store a count variable in a cookie on user's side (or use a session variable would be more convenient if you're using php).  Every time a user clicks on that add form, have that count added by one (take mod 18 to recycle count).  Display appropriate form based on the value of the count variable.

Cheers!
0
 

Author Comment

by:jmc430
ID: 9627050
Hi inq123,

Can you provide me with an example of how this is done?  I'm using perl ..

Do I use an if then statement and set the count variable equal to the form?

Thanks!
jmc430
0
 
LVL 8

Expert Comment

by:inq123
ID: 9631000
Hi, I just worked out this example for you.  Do note that there're other alternatives to your question like using javascript, but this approach below is more powerful.  Save the code below as cookie.pl in your server's main cgi-bin (url for this cgi-bin should be /cgi-bin).  Also note that if you're on unix you need to change the first line of code to #!/usr/bin/perl.  With my code below, with each button click the user can add one form, with a maximum of 18 forms.  When user reached 18 forms pressing "add" button will not add any more form and also will not decrease any form (unlike I said earlier, by using % 18 to recycle count, which would decrease form.  I think that's not desired).  If user instead of clicking add, clicked submit button in one of those 18 forms to submit an order, then they'll get an acknowledgement page.  I think that should be a complete enough example for you.  Now here's the code:

#!c:/Perl/bin/Perl.exe
use CGI qw/:standard/;
use CGI::Cookie;
use CGI::Carp qw(fatalsToBrowser);
use Dumpvalue;
use strict;

# Create new cookies and send them
my %cookies = fetch CGI::Cookie;
my ($cookie, $count);
if($cookies{'count'})
{
  $count = ($cookies{'count'}->value > 18)? 18 : $cookies{'count'}->value;
}
else
{
  $count = 0;
}
$cookie = new CGI::Cookie(-name=>'count',-value=>$count+1);
if(!param() || param('add')) # meaning that user first accessed this page or pressed add button
{
  print header(-cookie=>$cookie),
        start_html;
  # print the main form with an add button
  print <<"FORM";
    <form name=main method=post action=/cgi-bin/cookie.pl>
      <input type=submit name=add value=add>
    </form>
FORM
 
  for(my $i = 0; $i < $count; $i++)
  {
    print_form($i);
  }
}
else # user submitted an order using one of the 18 forms, then don't update cookie
{
  print header,
        start_html;
  print "we got your order!  Thank you.<br>\n";
}
print end_html;

sub print_form
{
  my $i = shift;
  print <<"FORM";
  <form name=myform$i method=post action=/cgi-bin/cookie.pl>
    <input type=text name=mystuff value=\"this is form #$i\">
    <input type=submit name=submit value=submit>
  </form>
FORM
}
0
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 8

Accepted Solution

by:
inq123 earned 2000 total points
ID: 9667933
jmc430,

It's been a week, got any result yet?
0
 

Author Comment

by:jmc430
ID: 11559333
Hi ing123,

Sorry for the delayed response..

I hope you're not upset with me!

Apologies again ... hope you have a good day!

jamie
0
 
LVL 8

Expert Comment

by:inq123
ID: 11560037
No, not upset at all.  If I were upset, I'd have made noise long time ago. :)

Thanks for the unexpected points!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

650 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