Gossamer Forum
Home : General : Perl Programming :

Multiple radio buttons

Quote Reply
Multiple radio buttons
Hello,

I am working on a small project that should be relatively simple, but I am hung up on one part. Users will be able to make posts using this script. Their entries will not appear on a publicly viewable page until the users entry has been approved by an admin. There will be many, many posts per day so I was wanting to list all of the entries on one page and next to the entry, have two radio buttons. One for approve, one for deny. After all of the entries have been reviewed, Id like to be able to click submit and have the ones I did not approve deleted from the DB. I can handle deleting/adding the entries, but I can't figure out how to process the form input since there will probably be 100+ radio buttons each being checked either yes or no. Any help would be GREATLY appreciated!

Quote Reply
Re: Multiple radio buttons In reply to
You could make each group of checkboxes have an name of the ID of the post...
I'd have something like this:

Code:
Post Subject No Action Approve Delete
(subject linked to the body) <input type=radio name=post_id value=no_action selected>
<input type=radio name=post_id value=approve>
<input type=radio name=post_id value=delete>
Then when you're parsing the input, just get a list of the post_id's which haven't been approved, and check this against the ones which have been submitted, performing the appropriate action.

Adrian
Quote Reply
Re: Multiple radio buttons In reply to
Adrian,

Thanks for the quick reply. Actually, that is exactly what I am doing. What I can not figure out how to do is handle all the input coming from the form. Like I said, I have 100+ radio buttons that will either be on or off for each potential post. Is there a way to process all of the buttons at once? If so, would you or someone mind posting a quick example of how to do this?

Thanks in advance.

Quote Reply
Re: Multiple radio buttons In reply to
Code:
foreach ($in->param()) {
if (/^\d+$/) {
if ($in->param($_) eq "delete") {
&delete;
}
}
}
Something like that anyway Laugh

I'm sure that's not the best way.

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Multiple radio buttons In reply to
Thanks paul, I still can't get the thing to work! Heres what Im doing:

The form input is like this
<input type="radio" value="keep" name="1548795689">
<input type="radio" value="delete" name="1548795689">
next entry
<input type="radio" value="keep" name="1548795690">
<input type="radio" value="delete" name="1548795690">
and so on....


sub setapproval {
foreach ($cgi->param()) {
if (/^\d+$/) {
if ($cgi->param($_) eq "delete") {
my $qy = "UPDATE tablename SET approval = '1' WHERE idnum = '$cgi->param($_)'";
$dbh->do($qy);
}
}
exit;
}}

Can anyone point me in the right direction?

Quote Reply
Re: Multiple radio buttons In reply to
Its probably my code Wink

.....but try changing:

my $qy = "UPDATE tablename SET approval = '1' WHERE idnum = '$cgi->param($_)'";

to
my $id = $cgi->param($_);
my $qy = "UPDATE tablename SET approval = '1' WHERE idnum =$id";

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Multiple radio buttons In reply to
Nope, STILL no luck. I messed with it for about 2 hours today and never even came close! Anyone else have any ideas?

Quote Reply
Re: Multiple radio buttons In reply to
Just taking a SWAG at this... but I'd look into some of the Links subroutines, from there you can hack down the one of the Admin sub's (it allows for exactly what you're looking for) to just a couple of radio buttons, click submit and accept/reject records. You can even send e-mails to those accepted/rejected.

I think it'll point you in the right direction, if nothing else.