View Full Version : Php Form Processing

08-18-2007, 03:45 AM
Hi there,

Ive done php form processing before, but there is something im stuck on.

I have a form, and a php while loop, that connects to the database, and prints rows of data.

<input type='checkbox' name='inboxcheck[";
echo $foo++;
echo "]' value='$row2[id]' />

So, it would print, say eg ...

<input type='checkbox' name='inboxcheck[1]' value='7' />
<input type='checkbox' name='inboxcheck[2]' value='11' />
<input type='checkbox' name='inboxcheck[3]' value='17' />
<input type='checkbox' name='inboxcheck[4]' value='20' />

So then i select the textboxes, say i select inboxcheck[2] and inboxcheck[4]

Then, it goes to the process.php page, and this is what i have...

$inboxcheck = stripslashes($inboxcheck);

echo $inboxcheck;

But, because i selected 2 and 4, instead of writing this...

$inboxcheck[2] = stripslashes($inboxcheck[2]);
$inboxcheck[4] = stripslashes($inboxcheck[4]);

echo $inboxcheck[2];
echo $inboxcheck[4];

I dont know what checkboxes users are going to select, so is there any way of displaying the values of all the checkboxes they select like...

$inboxcheck[numbers] = stripslashes($inboxcheck[numbers]);

echo $inboxcheck[numbers];

So as i selected 2 and 4, it will echo 11 and 20.


08-18-2007, 05:46 AM
This will remove empty items, and apply stripslashes to every item.

$inboxcheck = array_map('stripslashes', array_filter($_POST['inboxcheck']));
echo implode(' ', $inboxcheck);
The numbers will be separated by a space. You can check to see if the array is empty() before imploding it if you wish.

08-18-2007, 12:22 PM
Thanks! It works!