Create checkbox from a file

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
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Create checkbox from a file

Post by slash85 »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I'm currently trying to create checkboxs from a file. I'm doing the below:

Code: Select all

<?

$filename = "dummy.txt";
$handle = fopen($filename, "r")or die("Somthin is wrong");


$contents = fread($handle, filesize($filename));

echo "<form name=\"form1\" action=\"$self\" method=\"POST\">

<input type=\"checkbox\" name=\"option1\" value=\"$contents\">$contents<br><br>

<input type=\"submit\" value=\"Submit\">

</form>";


fclose($handle);

?>
In dummy.txt the values are:

test1
test2
test3


when i view the page threw the browser i get:

checkbox [] test1 test2 test3


what i'm after is:

checkbox[] test1 checkbox[] test2 checkbox[] test3


any help on this please?

Thanks in advance,

slash.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

You need to split the file up into an array at each new line.
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Post by slash85 »

Thanks for the quick reply.


Any chance of a nudge in the right direction code wise, as i'm not the cleverest of chaps.



Thanks,

Slash.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

i think you would have to use the explode function and then do a while or foreach statement.
Post Reply