gravityforms-repeater icon indicating copy to clipboard operation
gravityforms-repeater copied to clipboard

Lists and File Fields

Open kLOsk opened this issue 9 years ago • 6 comments

I don't see these types in your list of supported fields, so I believe this is why they don't work. The file field doesn't allow for file upload and the button doesn't work.

The list field works on the frontend but the submission within email is garbage and gets chopped off.

Can you confirm these issues?

kLOsk avatar Dec 20 '15 14:12 kLOsk

Hey Daniel! At the moment, neither of those fields are supported. I don't think it would be too hard to get lists to work inside of repeaters so I'll look into that a little more. However I think file uploads may be kind of difficult.

kodie avatar Dec 20 '15 19:12 kodie

Thanks man!

Daniel Klose http://www.daniel-klose.com http://blog.daniel-klose.com

On Dec 21, 2015, at 04:09, Kodie Grantham [email protected] wrote:

Hey Daniel! At the moment, neither of those fields are supported. I don't think it would be too hard to get lists to work inside of repeaters so I'll look into that a little more. However I think file uploads may be kind of difficult.

— Reply to this email directly or view it on GitHub https://github.com/kodie/gravityforms-repeater/issues/9#issuecomment-166147891.

kLOsk avatar Dec 21 '15 02:12 kLOsk

File uploads would be great.. At the moment i just ask for a zip file for all the repeating fields in the above form.. however, it would be a more elegant solution to have a single file upload for each repetition.

ryjogo avatar Mar 14 '16 08:03 ryjogo

Here's a patch to get file fields working.

Put this above "return maybe_serialize($value);" in class-gf-field-repeater.php function get_value_save_entry()

//-------------------------------------------------------------------------------------------|
      //  Parse repeater files
      //-------------------------------------------------------------------------------------------|
        $repeater_files = array();
        
        foreach($_FILES as $key => $file){
          
          if(empty($file['name'])){continue;}
          
          //
          //  Regular field key: input_48
          //  Repeater field key: input_32-1-2
          //  
          //  32: The field key
          //  1: Which repeater (if multiple on a page)
          //  2: Which row of the repeater, if multiple rows.
          //
                    
          $key = str_replace("input_", "", $key);
          $exploded_key = explode("-", $key);
          if(empty($exploded_key[1])){continue;}
          
          $field_key = $exploded_key[0];
          $repeater_key = $exploded_key[1];
          $repeater_row = $exploded_key[2];
          
          $repeater_files[$repeater_key][$repeater_row][$field_key] = $file;
          
        }
        
      //-------------------------------------------------------------------------------------------|
      //  End determining if any files were passed into repeater fields
      //-------------------------------------------------------------------------------------------|
      
      //-------------------------------------------------------------------------------------------|
      //  If there were files, save them and update the value
      //-------------------------------------------------------------------------------------------|
        
        $repeaterId = $dataArray['repeaterId'];
        if(!empty($repeater_files)){
          
          foreach($repeater_files as $repeater_key => $repeater_row){
            foreach($repeater_row as $row_key => $row){
              foreach($row as $field_key => $file){
                
                if($repeater_key == $repeaterId){
                  
                  //--Upload the file------------------------------------------------------------------------|
                    $uploaded = GF_Field_Repeater::repeater_upload_file($form['id'], $file);
                    
                    if(strpos($uploaded, "http") === 0){
                      $uploaded = "<a href='$uploaded'>View File</a>";
                    }
                    
                  //--Update the field value------------------------------------------------------------------------|
                    $value[$row_key][$field_key][0] = $uploaded;
                  
                }
                
              }              
            }
          }
        }
      //-------------------------------------------------------------------------------------------|
      //  End saving and updating value if files
      //-------------------------------------------------------------------------------------------|

Yawaki avatar May 01 '17 19:05 Yawaki

@Yawaki I'd be happy to accept a pull request!

kodie avatar May 08 '17 14:05 kodie

I looked over @Yawaki code but it didnt work for me. Perhaps gravity forms updated since this time.

I modified the code and I will submit a PR when I have a bit more time but here is the code for now in case someone stumbles on this.

Again put this code above "return maybe_serialize($value);" in class-gf-field-repeater.php function get_value_save_entry()

$repeater_files = array();

        foreach ($_FILES as $key => $file) {

            if (empty($file['name'])) {
                continue;
            }

            $key = str_replace("input_", "", $key);
            $exploded_key = explode("-", $key);
            if (empty($exploded_key[1])) {
                continue;
            }

            $field_key = $exploded_key[0];
            $repeater_key = $exploded_key[1];
            $repeater_row = $exploded_key[2];

            $repeater_files[$repeater_key][$repeater_row][$field_key] = $file;

        }

        $repeaterId = $dataArray['repeaterId'];
        if (!empty($repeater_files)) {

            foreach ($repeater_files as $repeater_key => $repeater_row) {
                foreach ($repeater_row as $row_key => $row) {
                    foreach ($row as $field_key => $file) {
                        if ($repeater_key == $repeaterId) {
                            $uploaded = GFFormsModel::upload_file($form['id'], $file);
                            $value[$row_key][$field_key][0] = $uploaded;
                        }
                    }
                }
            }
        }

philcook avatar Nov 20 '17 21:11 philcook