Gossamer Forum
Home : General : Perl Programming :

Perl/CGI and Buttons. Argh!

Quote Reply
Perl/CGI and Buttons. Argh!
Hi Folks

I have a few submit buttons on one page, so I'm trying to differenctiate between them, like GT have done with theirs <g>.

I have buttons like:

<input type="submit" name="action=edit_main&id=$ref->{id}" value="Edit">
<input type="submit" name="action=del_main&id=$ref->{id}" value="Delete">

etc.


However, when I hit submit on one of these buttons, the script doesn't recognise the sub-routine. I've tried GET and POST methods and it just doesn't want to recognise it.

The information it passes with a GET is obviously:

?action%3Dedit_main%26id%3D3%26=Edit

Which just comes up with an error that it can not find the sub routine.

However, if I actually type the URL into the browser, without the escape characters, like so:

?action=edit_main&id=3=Edit

It works fine. Which makes me wonder that my script doesn't like those escape characters.

Hmm. I'm missing something obvious here. Anyone have any ideas what is it?

Cheers

Wil


- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Why are you doing that?

The name should be name="add" and name="delete"

You differentiate between them inside the script.
Code:
if ($in->param('add')) {
_add();
}
elsif ($in->param('delete')) {
_delete();
}

Then you just have $ref->{id} as a hidden field.

Last edited by:

RedRum: Oct 22, 2001, 4:20 AM
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
Because I need a NAME and a VALUE pair, which a SUBMIT button doesn't allow you to have, because the VALUE must always be what is displayed in the browser.

Read the post again, Paul. Then look at the source code for this screen, the post reply screen or any other screen on the GT forum and then you can understand what I'm trying to achieve.

- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
....you can still do it like I suggested Crazy

WAFDA

Last edited by:

RedRum: Oct 22, 2001, 5:25 AM
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
Not really, because this is going to be a rather large program, and I want to simplify the code as easy as I can. Here's the code that acceept requests and determines what to do with them:
Code:
use CGI;

$query = new CGI;

$| = 1;

$query->import_names('A');

if ($A::action eq "login") { &login_prompt; } # login_prompt

elsif ($A::action eq "index") { &show_index; } # show index
elsif ($A::action eq "edit_main") { &edit_main; } # edit_main
elsif ($A::action eq "login_done") { &login_done; } # login_done

else { &login_prompt; } # login_prompt

exit;


Now if I go down your route, it's going to be a pain in the ass. I'll have to call my script with just

scriptname?delete

or

scriptname?edit

Which is not how I want it. I just need to find out, and know, why the script I am using doesn't recognise escape characters, which it should do(!).

Any more ideas?

Thanks.

- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Quote:
Now if I go down your route, it's going to be a pain in the ass. I'll have to call my script with just

scriptname?delete

or

scriptname?edit

What does that have to do with it? You are using a form. You either shove all the pairs into the submit button name as you've tried or you process it in the script - same difference.

You can even do it in one line.


Last edited by:

RedRum: Oct 22, 2001, 5:48 AM
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
Im guessing GT's custom CGI.pm is how they can do it Tongue
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
GT aren't using a custom version of Lincon's CGI.pm module. They are using their custom written ones.

What is annoying me, though, is that the code I have provided in this thread should theroticaly work without problem.



- wil
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
Because the way I'm doing things now is much cleaner, and as the script grows that is much more important to me.

I can easily remember sub calls, and urls, and I can make sure that I don't have to extract a name from somewhere in the URL on it's own. You suggest just using a value, which is not as stable as using a name/value pair.

- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Quote:
GT aren't using a custom version of Lincon's CGI.pm module. They are using their custom written ones.

Where did I say they were using Lincon's?
Quote Reply
Re: [RedRum] Perl/CGI and Buttons. Argh! In reply to
Quote:
Im guessing GT's custom CGI.pm is how they can do it

I miss-interpreted this line, sorry.

Reply with Quote feature would be handy on these boards!

- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Quote:
Reply with Quote feature would be handy on these boards!

Yeah someone mentioned that the other day - would save a bit of time.
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Anyone else got any ideas on how to get around this problem? Please?!

- wil
Quote Reply
Re: [Wil] Perl/CGI and Buttons. Argh! In reply to
Not sure if this gets at the issue, but...

Leave your value tags as is and change your name tags to just "action". When the form parses you should get something like:

action => Edit
or
action => Delete

depending on which button is clicked. You'd have to pass the id in another tag (hidden?). You can then handle the response based on the value of the action tag. Will that work?

You certainly can't put the ampersand in the name tag because this will throw off the parsing of the QUERY STRING.

Michael Coyne
seaturtle.org
Quote Reply
Re: [mcoyne] Perl/CGI and Buttons. Argh! In reply to
Aha! Thank you for that last piece of information.

Is that why GT use the ; symbol instead of the & sign then ???? Finally an explantation! :-))

The problem with this approach, is that I only want to open one FORM tag and close one FORM tag, and the script will churn out a hundred of these buttons from information on the database. And, the ID will be different for each button; therefore I can't go down that route.

Thank you for your input though !!!

- wil