我创建了一个简单的重力形式(id = 11),其中包含2个字段:
文本字段类型(名称=“ my_name”)
文件上传类型(我无法为其设置名称)
提交后我想使用此代码处理此表单。如何更改用于处理已提交文件的代码段? 请假设我必须亲自手动处理表格
$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));}
答案 0 :(得分:0)
要解决此问题,您可以按照以下代码
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'];);
}
}