Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

[SOLVED} Checkboxes In GridField




Community Member, 532 Posts

20 February 2013 at 6:39am

Edited: 21/02/2013 7:59am

I'm trying to create a form where a user can email selected files from a GridField, I had done something like this back in he day with a TableList Field, but I'm not sure how to augment teh gridfield witha column of checboxes, that the Submit action iterate through

Any guidance would be helpful


I figured it out, I created the following GridField Componant:

class GridFieldSelectBox implements GridField_ColumnProvider {
   public function __construct($useToggle = true, $targetFragment = 'before') {
      $this->targetFragment = $targetFragment;
      $this->useToggle = $useToggle;
   public function augmentColumns($field, &$cols) {
      if(!in_array('Select', $cols)) $cols[] = 'Select';
   public function getColumnsHandled($field) {
      return array('Select');
   public function getColumnContent($field, $record, $col) {
      if($record->canView()) {
         $data = new ArrayData(array(
            'ID' => $record->ID
         return $data->renderWith('GridFieldSelectItem');
   public function getColumnAttributes($field, $record, $col) {
      return array('class' => 'col-select');

   public function getColumnMetadata($gridField, $col) {
      return array('title' => "Select");

and this template to render the checkbox

<input id="File_$ID" class="checkbox" name="AttachedFiles[]" type="checkbox" value="$ID" />

I then added to the gridfield on the front end and I can iterate throught $data["AttachedFiles"] on the form action