Jump to content

[SOLVED] checkboxes


jb60606

Recommended Posts

I have a file (colors.txt) containing a list of colors

 

yellow

blue

red

purple

gray

 

The following code extracts the contents of the file and places it on a web page with a *checked* checkbox next to each element:

 

<?php

 

$colors = file("data/colors.txt");

sort($colors);

 

echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";

 

foreach($colors as $color){

 

echo "<input type=\"checkbox\" value=\"{$color}\" name=\"colors[]\" CHECKED>{$color}</input><br />\n";

 

}

 

echo " <input type=\"submit\" value=\"Submit\" name=\"submit\"/>\n";

 

echo "</form>\n";

 

?>

 

I would like to be able to remove colors from the file by simply unchecking it's corresponding checkbox.

 

Anyone have any recommendations on how to do this? I've been scouring the internet for a tutorial of some sort, on handling checkbox arrays, but turned up nothing.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/55440-solved-checkboxes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.