CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Help with checkboxes

 



mike
User

May 12, 2001, 6:26 PM

Post #1 of 4 (1576 views)
Help with checkboxes Can't Post

Hello,

OK, I have a little problem. I put together an admin section for my search script, which will allow me to view urls and allow me to multiply delete them with a checkbox. This is how the code looks to generate the checkboxes:

open (DATA, "base.txt");
@indata = <DATA>;
close (DATA);
foreach $entries (@indata){
($url, $title, $keywords, $email, $description) = split(/\::/, $entries);
print "<input type=checkbox name=urls value=$url>$url
\n";
}


Once this happens it shows a big list of urls with a checkbox next to them to delete the unwanted ones. Then I have this code in the sub to delete the checked boxes:

$urls = $INPUT'{urls'};
@userlist = split(/\,/, $urls);
open (DBASE, "base.txt");
@alluser = <DBASE>;
close (DBASE);
open (WDBASE, ">base.txt");
foreach $lines (@userlist) {
chomp ($lines);
foreach $alllines (@alluser) {
($url, $title, $keywords, $email, $description) = split(/\::/, $alllines);
unless ($lines eq $url) {
print WDBASE $alllines;
}
}
}
close (WDBASE);


My problem is that when you click delete and try to delete the checked boxes, it only deletes the entry of the last box checked, instead of all the ones you checked. So if I check 2 boxes, it only deletes 1 of them. Could you please help me, I don't know what is going wrong with it.

Mike




randor
User

May 16, 2001, 7:08 AM

Post #2 of 4 (1556 views)
Re: Help with checkboxes [In reply to] Can't Post

ok,

your problem seems to be in your html, not your perl,

when you create the checkboxes, you have created them all with 1 name "urls",

the problem with that is that when the html sends the info, it will only send 1 value for each name,
you have :
urls = www.mysite.com
urls = www.yoursite.com
urls = www.thiersite.com

so if they check more than one, it will ONLY send the last one checked, and throw out the rest. so what you need to do is to use different names for each value.

here is an example:

open (DATA, "base.txt");
@indata = <DATA>;
close (DATA);
$i = '0';
foreach $entries (@indata){
$i++;
($url, $title, $keywords, $email, $description) = split(/\::/, $entries);
print "<input type=checkbox name=$i value=$url>$url
\n";
}

then when you want to check for deletion, use a count to do so:

$urls = $INPUT'{urls'};
@userlist = split(/\,/, $urls);
open (DBASE, "base.txt");
@alluser = <DBASE>;
close (DBASE);
open (WDBASE, ">base.txt");
foreach $lines (@userlist) {
chomp ($lines);
$url++;
foreach $alllines (@alluser) {
($url, $title, $keywords, $email, $description) = split(/\::/, $alllines);
unless ($lines eq $INPUT'{$url}) {
print WDBASE $alllines;
}
}
}
close (WDBASE);

i did not test this, but it should work, let me know if it doesnt,

hope this helps.



mike
User

May 28, 2001, 1:36 PM

Post #3 of 4 (1533 views)
Re: Help with checkboxes [In reply to] Can't Post

Hello again,

well, I tried tha coding and this time it just deleted the whole database. So I re-uploaded the database, but I still have nothing to delete sites with. I think the problem with the code you supplied is that the code to check for deletion doesn't have anything to do with the HTML coding. The tag $INPUT{'urls'} isn't even submitted. I really need some help, so if you could help me out I would really appreciate it.



Bryde
newbie

Jun 23, 2001, 4:52 PM

Post #4 of 4 (1503 views)
Re: Help with checkboxes [In reply to] Can't Post

Hi,
There's no problem by calling the checkboxes
the same, as long as their value tag differs.
I just made a script myself using multiple
checkboxes and i have no problem when selecting
more than one.. Here's what i do:

use CGI;
$co = new CGI;
my @chkbox_selections = $co->param('chkboxname');
#then the array chkbox_selections contains
# the value of all checkboxes checked..


Hope that helps else just give me a holler.



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives