I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
}
but that just grabs the last entry in the group.
The line in question is:
<input type="checkbox" name="DeleteThi s" value="<?php
echo("$allfiles[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!" 29 3128
Amer Neely wrote:
I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
}
but that just grabs the last entry in the group.
The line in question is:
<input type="checkbox" name="DeleteThi s" value="<?php
echo("$allfiles[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
I've changed the code for the above line so the name now is unique for
each element. That now lets me grab whichever one/s are checked. But,
another problem has arisen.
I also have a JavaScript toggle to 'Select/Unselect All' checkboxes,
which works fine. But the 'checked' status doesn't seem to be getting
passed to the PHP code. So, when I display the items checked, it is
incorrect. Refreshing the page also doesn't seem to correct it. Only
physically clicking the checkboxes seems to work.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
Amer Neely wrote:
I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
}
but that just grabs the last entry in the group.
The line in question is:
<input type="checkbox" name="DeleteThi s" value="<?php
echo("$allfiles[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
in html, if your checkbox is called "blah123" then when its checked it
will have the variable name of blah123 with a value of blah123, if it
is unchecked then blah123==null. the easy way is:
if (!empty($_POST['blah123'])) { do stuff }
Flamer.
php is not to "grab" the checkboxes, it comes and goes as lessons for
the yum mathematical calus on webpage stuff!
Use the html to expose your own web pages!
Amer Neely wrote:
I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
}
but that just grabs the last entry in the group.
The line in question is:
<input type="checkbox" name="DeleteThi s" value="<?php
echo("$allfiles[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
flamer di******@hotmai l.com wrote:
Amer Neely wrote:
>I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear with me, things are a little different in that country.
I've tried: foreach ($_REQUEST as $field =$value) { echo "$field = $value<br>"; } but that just grabs the last entry in the group.
The line in question is: <input type="checkbox" name="DeleteThi s" value="<?php echo("$allfile s[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
in html, if your checkbox is called "blah123" then when its checked it
will have the variable name of blah123 with a value of blah123, if it
is unchecked then blah123==null. the easy way is:
if (!empty($_POST['blah123'])) { do stuff }
Flamer.
Hmmm. OK, so I will need to also walk through each of the new input
names, and check them with the 'empty' function. I'll work on that. Thanks.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
flamer di******@hotmai l.com wrote:
Amer Neely wrote:
>I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear with me, things are a little different in that country.
I've tried: foreach ($_REQUEST as $field =$value) { echo "$field = $value<br>"; } but that just grabs the last entry in the group.
The line in question is: <input type="checkbox" name="DeleteThi s" value="<?php echo("$allfile s[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
-- Amer Neely w: www.softouch.on.ca/ b: www.softouch.on.ca/blog/ Perl | MySQL programming for all data entry forms. "We make web sites work!"
in html, if your checkbox is called "blah123" then when its checked it
will have the variable name of blah123 with a value of blah123, if it
is unchecked then blah123==null. the easy way is:
if (!empty($_POST['blah123'])) { do stuff }
Flamer.
I can now grab the selected elements, but only if they are selected by
mouse clicks. If I use the JavaScript toggle to select/unselect all,
nothing gets passed to the PHP. This works in Perl, so it has to be
doable in PHP I would think.
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
..oO(flamer di******@hotmai l.com)
>in html, if your checkbox is called "blah123" then when its checked it will have the variable name of blah123 with a value of blah123
It will have the value of the 'value' attribute.
>if it is unchecked then blah123==null.
If unchecked then the checkbox is not submitted at all.
Micha
..oO(Amer Neely)
>I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files.
Only checked checkboxes will be submitted by the browser.
>Does each checkbox name have to be unique?
No, you can use the same name, but different values. To make this work
in PHP you have to add brackets to the name, see below.
>I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
} but that just grabs the last entry in the group.
The line in question is: <input type="checkbox" name="DeleteThi s" value="<?php echo("$allfile s[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
Some things:
1) You should not use $_REQUEST. This array contains data from different
sources, so you don't know where all the values actually came from. Use
the array that corresponds with the used method in your form, which
should be $_POST in this case.
2) Instead of $allfiles[$i] you can just use the variable $i as the
value of your checkboxes, that's enough. When processing the form use
that value to lookup the filenames in your $allfiles array.
3) To process multiple form controls that share the same name you have
to add square brackets to their name, e.g. "DeleteThis[]". This causes
PHP to store all the values in an array instead of a scalar.
So the code could look something like this:
if (isset($_POST['DeleteThis')) {
foreach ($_POST['DeleteThis'] as $index) {
if (isset($allfile s[$index])) {
// perform action to delete the file
}
}
}
The code for the checkboxes like I would probably write it:
printf("<label> <index type='checkbox' name='DeleteThi s[]'
value='%u'>&nbs p;%s</label><br>\n", $i, $allfiles[$i]);
HTH
Micha
script, not html, this way post becomes fully clear.
Rogats wrote:
php is not to "grab" the checkboxes, it comes and goes as lessons for
the yum mathematical calus on webpage stuff!
Use the html to expose your own web pages!
Amer Neely wrote:
I've got a dynamically built form with checkboxes for each element ( a
list of file names in a directory). I need to grab only those checkboxes
that are checked, so I can then delete those files.
Does each checkbox name have to be unique? I was hoping to just group
them under one name, and select from that array.
PHP is not my native language - I'm coming at this from Perl, so bear
with me, things are a little different in that country.
I've tried:
foreach ($_REQUEST as $field =$value)
{
echo "$field = $value<br>";
}
but that just grabs the last entry in the group.
The line in question is:
<input type="checkbox" name="DeleteThi s" value="<?php
echo("$allfiles[$i]")?>"> <?p hp echo("$allfiles[$i]")?><br>
--
Amer Neely
w: www.softouch.on.ca/
b: www.softouch.on.ca/blog/
Perl | MySQL programming for all data entry forms.
"We make web sites work!"
after you succeed, post your reply, I want to know how also.
Amer Neely wrote:
>
Hmmm. OK, so I will need to also walk through each of the new input
names, and check them with the 'empty' function. I'll work on that. Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Angelos |
last post by:
I have this list of logs stored in a MySQL DB.
I display them in a list and next to each log I have a del view LINK
I want to add Checkboxes next to each log and keep del and view links as
well.
Then you can select all the logs you want to delete, hit a delete Link and
send the variables in a script...
Can you do that without having a form ?
|
by: Jack |
last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that
builds the sql string.
In the front end asp page, the checkbox code is written as follows:
<i><input type="checkbox" name="chk_Complete" value="<%Response.Write
l_IsChecked%>"<%if cbool(l_IsChecked) then Response.Write " checked"%>>
The code to captures the checkbox value in the asp page that builds the sql
string is follows
|
by: Vanessa |
last post by:
I have an ASP script which is used to upload files with Persits.Upload.1
object. But I can't get the values from mutliple checkboxes in the form like
normally.
<form method="post" ENCTYPE="multipart/form-data"....>
<input type="checkbox" name="language" value="English">English
<input type="checkbox" name="language" value="Spanish">Spanish
<input type="checkbox" name="language" value="Chinese">Chinese
Please advice!
|
by: evanburen |
last post by:
I'm passing the name of a div and the name of checkbox to this function
which either hides or displays the div. My problem is this line
// var the_box = window.document.frmCheckboxes.chkCompanyBoard;
I want to assign the name of the checked checkbox to var the_box rather
than just hard-code chkCompanyBoard
function hideLayer2(whichLayer,the_box)
|
by: J Talbot |
last post by:
Hi
Was wondering if anyone could help me with this problem :
If I have three checkboxes with different values on a form like :
<input type="checkbox" name="checkbox" value="1stValue">
<input type="checkbox" name="checkbox" value="2ndValue">
<input type="checkbox" name="checkbox" value="3rdValue">
| |
by: cyberdawg999 |
last post by:
Greetings all in ASP land
I have overcome one obstacle that took me 2 weeks to overcome and I
did it!!!!!
I am so elated!! thank you to all who invested their time and energy towards helping me with my problems.
Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame.
Now the second part is my new problem is that I want that the next time that page loads for...
|
by: txguy |
last post by:
have a page with lotsa checkboxes, am using javascript to count the number of boxes checked and to total the prices for all boxes checked. would like to pass the "description" of each checkbox but cant get the code to trap this field.
here's what the checkbox looks like ...
<input type="checkbox" name="C02074" id="C02074" value=1 descrip="size, color, number, etc, @73.60" item="02074" price="73.60" yes="yes"...
|
by: LionsDome |
last post by:
Hello,
I have a vb.net page which a bunch of checkboxes. A user can select a
checkbox(s) and hit the submit button to store those values in a SQL
Server table. This works fine with no problem the first time the user
submits. However when user submits a second time while changing some
of the selected boxes the page only re-submits the previosly selected
checkbox values. It's like its storing it somewhere in the cache or
something. My...
|
by: raamay |
last post by:
I have six checkboxes as shown below:
<table>
<tr>
<td><input name="spec1" type="checkbox" value="0" tabindex="11" /><label id="label">Bridge Construction</label></td>
</tr>
<tr>
<td><input name="spec2" type="checkbox" value="1" tabindex="12" /><label id="label">Building Construction</label></td>
</tr>
<tr>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |