[mod] Display Check Boxes of a CheckBoxGroup in the same row

3rd party code for phpList

[mod] Display Check Boxes of a CheckBoxGroup in the same row

Postby seisys » 12:02am, Thu 29 Nov, 2007

I was wondering why the Check Boxes in a CheckBoxGroup were displaying on seperate rows since I wanted to display them on the same row.

So I looked at the code in subscribelib2.php located in the admin folder and made the following change in the case "checkboxgroup": section of the function ListAttributes to display the check boxes in the same row:

I left the original code in place but commented out the lines that are not needed. You can replace the entire case statement with:
Code: Select all
       case "checkboxgroup":
          $output[$attr["id"]] .= sprintf("\n".'<tr><td><div>%s</div>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));//this is the beginning of the question text
          $values_request = Sql_Query("select * from $table_prefix"."listattr_".$attr["tablename"]." order by listorder,name");
          $output[$attr["id"]] .= sprintf('</td></tr>');//this is the end of the question text
            $output[$attr["id"]] .= '<tr><td>';
          while ($value = Sql_Fetch_array($values_request)) {
            if (is_array($_POST[$fieldname]))
              $selected = in_array($value["id"],$_POST[$fieldname]) ? "checked" : "";
            else if ($data[$attr["id"]]) {
              $selection = explode(",",$data[$attr["id"]]);
              $selected = in_array($value["id"],$selection) ? "checked":"";
            }
            //$output[$attr["id"]] .= sprintf('<tr><td>test<input> %s</td></tr>',$fieldname,$value["id"],$selected,stripslashes($value["name"]));//this displays each check box in a seperate row
            $output[$attr["id"]] .= sprintf('<input> %s',$fieldname,$value["id"],$selected,stripslashes($value["name"]));//this displays each check box in the same row
          }
            $output[$attr["id"]] .= '</td></tr>';
          break;


If anyone has any comments, like I missed something or a better way to implement this, please let me know.
seisys
phpList newbie
 
Posts: 4
Joined: 2:39am, Mon 29 Oct, 2007

Great tip!

Postby hwestgate » 10:14pm, Wed 14 May, 2008

Hey thanks for this. I was trying to figure this out too, but I wanted to be able to create a grid of checkboxes, and control where the line breaks appear. I managed to do it, probably not pretty code, but it works. Putting your extra line in an if/else statement allows you to define attribute names that trigger line breaks - I used "break," "break2," and "break3." Here's the modified code...

Code: Select all
case "checkboxgroup":
    $output[$attr["id"]] .= sprintf("\n".'<tr><td><div>%s</div>',$attr["required"] ? 'required' : 'attributename',stripslashes($attr["name"]));
    $values_request = Sql_Query("select * from $table_prefix"."listattr_".$attr["tablename"]." order by listorder,name");
    $output[$attr["id"]] .= sprintf('</td></tr>');
    while ($value = Sql_Fetch_array($values_request)) {
        if (is_array($_POST[$fieldname]))
            $selected = in_array($value["id"],$_POST[$fieldname]) ? "checked" : "";
        else if ($data[$attr["id"]]) {
            $selection = explode(",",$data[$attr["id"]]);
            $selected = in_array($value["id"],$selection) ? "checked":"";
        }
        if (stripslashes($value["name"])=="break" || stripslashes($value["name"])=="break2" || stripslashes($value["name"])=="break3")
       $output[$attr["id"]] .= sprintf('<tr><td></tr></td>');
        else
       $output[$attr["id"]] .= sprintf('<td><input> %s</td>',$fieldname,$value["id"],$selected,stripslashes($value["name"]));
    }
break;


Using this, you can arrange the checkboxes in a 1, 2, or 3-row grid (more if you add more test conditions to the last if statement). So, if you defined the values for a checkboxgroup named "Grid" as "1," "2," "3," "break," "4," "5," "break2," "6," "break3," "7," "8," you'd see something like this...

Grid
1 2 3
4 5
6
7 8
hwestgate
phpList newbie
 
Posts: 1
Joined: 10:07pm, Wed 14 May, 2008

Re: [mod] Display Check Boxes of a CheckBoxGroup in the same

Postby futurelabs » 12:22pm, Tue 27 Sep, 2011

i was trying this mod but for the new version its not working.
Any Idea ?

Andrew
futurelabs
phpList newbie
 
Posts: 3
Joined: 2:32pm, Sat 13 Mar, 2010

Re: [mod] Display Check Boxes of a CheckBoxGroup in the same

Postby hsodhi » 5:52pm, Sun 19 Aug, 2012

Hi !

Am new to PHP and do not know any programming ...

Have setup a PHP list on my server with Checkbox Groups with lot of checkboxes in each. Works fine !

But, instead of all checkboxes one in a row, would like them in say rows of 3 each so as to reduce the scroll .

Tried implementing suggestions here but didn't work :-(

I am on PHP version 2.10.17

Any suggestions ? All help appreciated !

HS
hsodhi
phpList newbie
 
Posts: 3
Joined: 5:41pm, Sun 19 Aug, 2012


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 1 guest

cron