Jump to content

help with form with checkbox


nerya

Recommended Posts

<?php

if(isset($_POST['submit']))

{

//here i want to write all the  checkbox that choose

}

?>

<form action='2.php' method='post'>

<input type="checkbox" name="check" value='1'> <br>

<input type="checkbox" name="check" value='2'><br>

<input type="checkbox" name="check" value='3'><br>

<input type="checkbox" name="check" value='4'><br>

<input type="checkbox" name="check" value='5'><br>

<br><input type='submit'name='submit' value='שלח'>

</form>

 

how i do that??

if I check one by one it's not good because in the real code I have over of 100  checkbox

so...is there a way to write all checkbox that choose??

 

thank.

Link to comment
Share on other sites

give the checboxes differrent names

 

then

 

$checkbox1 = $_POST["checkbox1"];

$checkbox2 = $_POST["checkbox2"];

 

and so on

ok

it's impassable to run "for" and do something like that..

 

for(I=0;I<100;I++)

    {

        $checkbox = $_POST["checkbox  "I"  "];

    }

/////here I creat array and put what I got from the form

the problem is how I do that $_POST["checkbox  "I"  "];

 

thank

Link to comment
Share on other sites

or just write

 

<input type="checkbox" name="check[]" value="1" />

 

in php you could access it in this manner:

 

<?php

 

echo $_POST['check'][0]; // 1

 

?>

ohhh smart

 

I prefer to use implode(', ', $_POST['check'])); which will turn the array into a string, with the values being separated by comma's. Or you could loop through them using a foreach loop, if you want to automate things a bit.

 

Link to comment
Share on other sites

or just write

 

<input type="checkbox" name="check[]" value="1" />

 

in php you could access it in this manner:

 

<?php

 

echo $_POST['check'][0]; // 1

 

?>

ohhh smart

 

I prefer to use implode(', ', $_POST['check'])); which will turn the array into a string, with the values being separated by comma's. Or you could loop through them using a foreach loop, if you want to automate things a bit.

 

I will be happy if you explain with code what did you tried to say

thank

Link to comment
Share on other sites

I tried to do that

 

 

<?php

if (isset($_POST['del]))

{ echo $_POST['array[0]'];

}

?>

 

 

echo"<br><br><br>

<form action='2.php' method='post'>

<input type='hidden' name='array[]' value='1'/>

<br><input type='submit' name='del' value='ccc'></form>";

 

 

but it's not write anything

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.