Esempio n. 1
0
    public static function is_empty($field, $form_id=0){

        if(empty($_POST["is_submit_" . $field["formId"]])){
            return true;
        }

        switch(RGFormsModel::get_input_type($field)){
            case "post_image" :
            case "fileupload" :
                $input_name = "input_" . $field["id"];

                if(rgar($field, "multipleFiles")){
                    $uploaded_files = GFFormsModel::$uploaded_files[$form_id];
                    $file_info = rgar($uploaded_files, $input_name);
                    return empty($file_info);
                } else {
                    $file_info = GFFormsModel::get_temp_filename($form_id, $input_name);
                    return !$file_info && empty($_FILES[$input_name]['name']);
                }
              break;

            case "list" :
                $value = rgpost("input_" . $field["id"]);
                if(is_array($value)){
                    //empty if all inputs are empty (for inputs with the same name)
                    foreach($value as $input){
                        if(strlen(trim($input)) > 0 )
                            return false;
                    }
                }

                return true;

        }

        if(is_array($field["inputs"]))
        {
            foreach($field["inputs"] as $input){
                $value = rgpost("input_" . str_replace('.', '_', $input["id"]));
                if(is_array($value) && !empty($value)){
                    return false;
                }

                $strlen = strlen(trim($value));
                if(!is_array($value) && strlen(trim($value)) > 0)
                    return false;
            }
            return true;
        }
        else{
            $value = rgpost("input_" . $field["id"]);
            if(is_array($value)){
                //empty if any of the inputs are empty (for inputs with the same name)
                foreach($value as $input){
                    if(strlen(trim($input)) <= 0 )
                        return true;
                }
                return false;
            }
            else if($field["enablePrice"]){
                list($label, $price) = explode("|", $value);
                $is_empty = (strlen(trim($price)) <= 0);
                return $is_empty;
            }
            else{
                $is_empty = (strlen(trim($value)) <= 0) || ($field["type"] == "post_category" && $value < 0);
                return $is_empty;
            }
        }
    }
 public function get_single_file_value($form_id, $input_name)
 {
     global $_gf_uploaded_files;
     GFCommon::log_debug(__METHOD__ . '(): Starting.');
     if (empty($_gf_uploaded_files)) {
         $_gf_uploaded_files = array();
     }
     if (!isset($_gf_uploaded_files[$input_name])) {
         //check if file has already been uploaded by previous step
         $file_info = GFFormsModel::get_temp_filename($form_id, $input_name);
         $temp_filepath = GFFormsModel::get_upload_path($form_id) . '/tmp/' . $file_info['temp_filename'];
         if ($file_info && file_exists($temp_filepath)) {
             $_gf_uploaded_files[$input_name] = $this->move_temp_file($form_id, $file_info);
         } else {
             if (!empty($_FILES[$input_name]['name'])) {
                 $_gf_uploaded_files[$input_name] = $this->upload_file($form_id, $_FILES[$input_name]);
             } else {
                 GFCommon::log_debug(__METHOD__ . '(): No file uploaded. Exiting.');
             }
         }
     }
     return rgget($input_name, $_gf_uploaded_files);
 }
 public static function get_uploaded_file_info($form_id, $input_name, $field)
 {
     // hack alert: force retrieval of unique ID for filenames when continuing from saved entry
     if (self::is_save_and_continue() && !isset($_POST['gform_submit'])) {
         $is_gform_submit_set_manually = true;
         $_POST['gform_submit'] = $form_id;
     }
     $uploaded_files = isset(GFFormsModel::$uploaded_files[$form_id][$input_name]) ? GFFormsModel::$uploaded_files[$form_id][$input_name] : array();
     $file_info = self::is_multi_file_field($field) ? $uploaded_files : GFFormsModel::get_temp_filename($form_id, $input_name);
     if (self::is_save_and_continue() && !isset($_POST['gform_submit'])) {
         $_POST['gform_submit'] = $form_id;
     }
     // hack alert: force retrieval of unique ID for filenames when continuing from saved entry
     if (isset($is_gform_submit_set_manually)) {
         unset($_POST['gform_submit']);
     }
     return $file_info;
 }