Checkbox in PHP

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
roeio
Forum Newbie
Posts: 9
Joined: Mon Apr 16, 2012 4:01 am

Checkbox in PHP

Post by roeio »

Hey,

I have made a PHP array that parses a XML file and bulding a table from all the informations parsed from the XML file. EX:

Hostname Host S/N Process Comments Highlight CLICK TO SUBMIT BUTTON
Myhost01 3341221 Backup Finish in an hour [Checkbox]

Now, I want to make a checkbox button where the [Checkbox] is mentioned that when I check the Checkbox and click the submit button it will keep my checkbox checked with a V mark.

Now, my problem is that I print the "checkbox" inside the for loop so it will print it at the "Highlight" colums in each row, but I can't get it to keep after I'm clicking the button...

This is how it goes:

Code: Select all

$f = fopen ( $filename, 'r' );
                 for ($i = 0; $i < $filecount; $i++){
                        $hostname = $xml->box[$i]->hotname;
                        $operation = $xml->box[$i]->operation;
                        $version = $xml->box[$i]->version;
                        $cellnum = $xml->box[$i]->cell;
                        $ishold = substr($cellnum, 6);
                        $nXX = $ishold;
                        $textarea = $xml->box[$i]->notes;

date .=<div id=div1><th>$hostname</th><th>$operation</th><th>$version</th><th><input type=checkbox name=$nXX value=checkbox </th><th align=left><input type=checkbox align=left name=$cellnum value=1>$textarea</th></tr></div>";

        // starting to print the table header
        echo ('<TR bgcolor=teal align="center">
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>Hostname</font></strong></th>
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>Host S/N</font></strong></th>
        <th width="4%" bgcolor=teal><font color=#FFFFFF><strong>Process</strong></th>
        <th width="3%" padding="2" bgcolor=teal><font color=#FFFFFF><strong>Comment</strong></th>
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>Highlight</strong></th>
        <th width="17%" align=center bgcolor=teal><font color=#FFFFFF><form name="Notes" action="hosts.php" method="post">Time:&nbsp');
        echo date("Y-m-d H:i");
        echo ('&nbsp &nbsp &nbsp<input type="submit" value="Click to Submit"></th>
        </tr></strong>');

        print $data;

echo "</table>"
How can I implement it in my PHP code?
bittiez
Forum Newbie
Posts: 1
Joined: Tue Jun 26, 2012 9:32 am

Re: Checkbox in PHP

Post by bittiez »

Well first of all shouldn't this

Code: Select all

date .=<div id=div1><th>$hostname</th><th>$operation</th><th>$version</th><th><input type=checkbox name=$nXX value=checkbox </th><th align=left><input type=checkbox align=left name=$cellnum value=1>$textarea</th></tr></div>";
be data .=? Sense your printing data?

Second, to make a checkbox checked just add checked="checked" to the checkbox input

A simple way you could keep them checkmarked(I haven't tested this) would be to pick something that is unique to each of your rows in your table, make that the value for the checkbox for that row, then when writing the part above check to see if that unique value is one of the ones that was checked, if it was then do data .= all your data plus checked="checked" else the data .= you would normally add
roeio
Forum Newbie
Posts: 9
Joined: Mon Apr 16, 2012 4:01 am

Re: Checkbox in PHP

Post by roeio »

Hey,

Thanks for your reply but I could understand what should I do, I cant understand how the "click to submit" will mark the checkbox as checked.
Post Reply