Php 如何处理包含单个文件的已提交重力表
我创建了一个简单的重力表单(id=11),其中包含两个字段:Php 如何处理包含单个文件的已提交重力表,php,wordpress,gravityforms,Php,Wordpress,Gravityforms,我创建了一个简单的重力表单(id=11),其中包含两个字段: 文本字段类型(name=“my_name”) 文件上载类型(我无法设置它的名称) 还有一个代码,我想在提交后用于handel此表单。如何更改此代码段以处理提交的文件? 请假设我必须自己手动处理表单 $input_1 = $_POST['myname']; //how to get sbmitted file? //$file = ? $array_of_inputs = array("input_1" => $input
$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));}
要解决此问题,您可以遵循以下代码
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'];);
}
}
您想要保存在输入文本框中的重力值form@Jinesh我想保存(文本框)和(文件)您想保存重力表单数据right@Jinesh是的,这是true@Jinesh您的代码是否保存提交的文件?表单中有两个字段(文本和文件类型)。请记住,我创建了html表单dynamicali,无法为该文件指定名称