Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does a cgi program handle a form that has two buttons? 3

Status
Not open for further replies.

jacksondorado

IS-IT--Management
Apr 12, 2001
135
US
Hi,

I have a simple email text box on a form and there is a 'subscribe' button that writes the email address to a text file. I would like to add an 'unsubscribe' button to the form and when a user types in their email and clicks 'unsubscribe' the program parses the text file and does compare string to find the email and delete it.

How do I handle two form buttons in one form? I'm pretty much at a cut and paste CGI writing level.

thanks
 
i had the same problem and at the end i has left one submit button. And in a script check if there is this e-mail:
yes - unsubscribe
no - subscribe
 
I am not sure I understand.

Do you mean to make a radio button choice on the form with unsubscribe and subscribe for choices and then only have a single button to submit the form?
 
<form>
<input type=text name=email>
<input type=submit value='subscribe'>
</form>

in the CGI script
1) open file with emails
2) check new email address:
if we have this address - unsubscribe them
if no - subscribe
 
this is a bit unconventional... but i think it should work.

<script>
function doSubmit(x) {
document.myForm.method=&quot;POST&quot;;
if (x == 1)
document.myForm.action=&quot;subscribe.cgi&quot;;

else
document.myForm.action=&quot;unsubscribe.cgi&quot;;

document.myForm.submit();
}
</script>

<body>
<form name=&quot;myForm&quot;>
<input type=&quot;button&quot; value=&quot;Subscribe&quot; onClick=&quot;doSubmit(1);&quot;><input type=&quot;button&quot; value=&quot;Unsubscribe&quot; onClick=&quot;doSubmit(2);&quot;>
</form>

depending on which button the user clicked... a value is passed to a javascript function and the appropriate script is called.
 
Kijori: that's the way I've handled calling different cgi programs from the same form. Good advice!

You can also use the same technique to call a single cgi program, and set a hidden variable to tell the cgi program what action to perform. That technique is useful if the different actions use a lot of the same program code - you can keep all the similar code in one program that way. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
tsdragon: thanks for the complement! :) never knew newbie like me can produce something...

anyway, i'll help whenever i can. learning day by day as it comes...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top