0
重力フォームを持つウェブサイト用のモバイルアプリを開発し、重力フォームのweb apiで入力できますが、ウェブサイトではフォームを送信するときにフォームがあるので自動的に新しい投稿を作成しますいくつかのポストフィールドがあり、Web APIを介して新しいエントリを追加すると、ポストではなくエントリが追加されます。 このエントリを重力フォームweb api経由で投稿する必要があることをどのように定義できますか?重力フォームweb ap経由でエントリーを追加した後に投稿
更新:そのフォームがポストフィールドを持っている場合、それが形成を通じて
重力フォームがポストを作成することができます。 read more
この機能は送信フォーム用であり、ウェブAPI経由でアクセスすることはできません。
$api_key = 'your_public_key';
$private_key = 'your_private_key';
//set route
$route = 'entries'; // or 'forms/{formID}/entries'
//creating request URL
$expires = strtotime('+1 day');
$string_to_sign = sprintf('%s:%s:%s:%s', $api_key, 'POST', $route, $expires);
$sig = calculate_signature($string_to_sign, $private_key);
$url = 'http://your_domain.com/gravityformsapi/' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires;
if(isset($_POST)){
$body = [
[
"form_id"=> "1", // if $route is just 'entries'
'1' => "Post Title" ,
'2' => "Post Content"
]
//,[ another entry ]
];
$response = wp_remote_post($url,['body'=>json_encode($body)]);
if (is_wp_error($response)) {
wp_send_json_error($response->get_error_message());
} else {
$body = json_decode($response['body'],true);
if($body['status'] === 201){
foreach($body['response'] as $entry_id){ //get each entry ID
$entry = GFAPI::get_entry($entry_id);
if(!is_wp_error($entry)){
$form = GFAPI::get_form(rgar($entry,'form_id'));
if($form)
GFCommon::create_post($form, $entry); //Finally add Post.
else
wp_send_json_error("can not find entry form.");
}else
wp_send_json_error($entry->get_error_message());
}
wp_send_json_success("Success!");
}else{
wp_send_json_error($body);
}
}
}else
wp_send_json_error("request body invalid");