как обработать гравитационную форму, содержащую файл сингла - PullRequest
3 голосов
/ 18 июня 2019

я создал простую гравитационную форму (id = 11), которая содержит 2 поля:

  1. тип текстового поля (name = "my_name")

  2. fileupload type (я не могу установить для него имя)

и есть код, который я хочу использовать для передачи этой формы после отправки.как изменить этот фрагмент для файла Handeling? Пожалуйста, предположим, что я должен сам выполнить ручную обработку формы

$input_1 = $_POST['myname'];


//how to get sbmitted file?
//$file = ?


$array_of_inputs = array("input_1" => $input_1 , "file_name" => $file);


$gravity_submit_result = submit_in_gravity_form(11 , $array_of_inputs , $api_key , $private_key ,$web_url); 
if ($gravity_submit_result){
    $response['message'] = $body['response'];
    $response['status'] = 'ok';
}
else{
    $response['status'] = false;
}
exit(json_encode($response));}

эта страница содержит мою гравитационную форму

1 Ответ

0 голосов
/ 18 июня 2019

Для решения этой проблемы вы можете воспользоваться этим кодом

  add_action( 'gform_after_submission', 'set_post_content', 10, 2 );
        function set_post_content( $entry, $form ) {

            //if the Advanced Post Creation add-on is used, more than one post may be created for a form submission
            //the post ids are stored as an array in the entry meta
            $created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );
            foreach ( $created_posts as $post )
            {
                $post_id = $post['post_id'];
                $post = get_post( $post_id );
              require_once( ABSPATH . 'wp-admin/includes/image.php' );
              require_once( ABSPATH . 'wp-admin/includes/file.php' );
              require_once( ABSPATH . 'wp-admin/includes/media.php' );
              $attach_id = media_handle_upload('file', $post_id);
              if (is_numeric($attach_id)) {
                 update_option('option_image', $attach_id);
                 update_post_meta($post_id, '_my_file_upload', $attach_id);
}
                update_post_meta($post_id, 'myname', $_POST['myname'];);
            }
        }
...