Page 1 of 1

Create checkbox from a file

Posted: Tue Mar 14, 2006 6:26 am
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]

Posted: Tue Mar 14, 2006 6:34 am
by Grim...
You need to split the file up into an array at each new line.

Posted: Tue Mar 14, 2006 6:40 am
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.

Posted: Tue Mar 14, 2006 6:50 am
by a94060
i think you would have to use the explode function and then do a while or foreach statement.