Checkboxes!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Checkboxes!!

Post by AlbinoJellyfish »

I have a page with about 10 checkboxes, is there a way i can enter them into an array, then on a later page, separate them so my script can check the prices and then add it together?

If you need more info just ask.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

Code: Select all

<input type="checkbox" name="arrayї]" value="whatever1">
<input type="checkbox" name="arrayї]" value="whatever2">
<input type="checkbox" name="arrayї]" value="whatever3">
<input type="checkbox" name="arrayї]" value="whatever4">
<input type="checkbox" name="arrayї]" value="whatever5">
to process them

Code: Select all

<?php
foreach($_POST['array'] as $key => $value)
{
echo $key." => ".$value."<br />";
}
?>
Last edited by qads on Thu Sep 23, 2004 7:10 pm, edited 1 time in total.
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Post by AlbinoJellyfish »

Code: Select all

<strong>Protocols:</strong>
      <br>
        <input name="array&#1111;]"  type="checkbox" id="r2" value="r2"> 
        R2   
   			&nbsp;&nbsp;&nbsp;
        <input name="array&#1111;]" type="checkbox" id="gr303" value="gr303">
GR-303        
<input name="array&#1111;]"  type="checkbox" id="idsn" value="idsn"> 
IDSN-PRI 
        <input name="array&#1111;]" type="checkbox" id="v5" value="v5">
        V5        
      <br>
    <input name="array&#1111;]" type="checkbox" id="tr08" value="tr08">
    TR08
    <input name="array&#1111;]" type="checkbox" id="calea" value="calea">        
      CALEA          
          <input name="array&#1111;]" type="checkbox" id="ss7" value="ss7">
Like that?

NVM its $_POST
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

yes but

Post by phpScott »

yes that is it but you don't need to use the word array you can use what ever you want as long as it is constant.

I would also name all the ID tags the same with out using the [] like the name tag that way you can use javascript and process the checkboxes as an array if need be.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Tutorial Section: viewtopic.php?t=23586
Post Reply