我正在做一个小项目,我将从wordpress中的重力形式插件接收信息,然后将该信息解析为谷歌表。 到目前为止,我能够毫无问题地做到这一点。当其中一个字段是文件上载字段(要上载的最大文件数为2)时,会出现此问题。链接如下所示:“www.example.org/wp-content-uploads/gravityforms/image1.jpg","www.example.org/wp-content-uploads/gravityforms/image1.jpg”< / p>
我希望它能做的是 !(http://imgur.com/a/BUXvn)!
它将在医生源列(第3列)中显示完整字符串,然后使用逗号作为分隔符将其拆分为2并在医生image1和doctor image2中显示。
这是我用来在php中解析的代码。
add_action('gform_after_submission_1', 'add_to_google_spreadsheet', 10, 2);
function add_to_google_spreadsheet($entry, $form) {
// This is the web app URL of your Google Script create in previous step
$post_url = 'https://script.google.com/macros/s/AKfycbwFTe3H0w8bp_2yviORAGhNZzIwvmKmdaCHf KEOdORwjO6pJPQ/exec';
// Put all the form fields (names and values) in this array
$doctor=('doctor source => rgar($entry,3)');
$doctorimage= explode(",",$doctor);
$body = array('first name' => rgar($entry, '1'), 'last name' => rgar($entry, '2'),'doctor source' => rgar($entry, '3'),'doctor image1' => rgar($doctorimage[0], '4'),'doctor image2' => rgar($doctorimage[1], '5'),);
// Send the data to Google Spreadsheet via HTTP POST request
$request = new WP_Http();
$response = $request->request($post_url, array('method' => 'POST', 'sslverify' => false, 'body' => $body));
}
rgar:重力形成用法 返回数组中的值 用法 rgar($ array,$ name);
对于任何想要这样做的人,这是我使用的指南:https://ctrlq.org/code/20047-gravity-forms-to-google-spreadsheet
答案 0 :(得分:1)
我相信只需要解决一些小的格式/逻辑问题。
鉴于您提供的信息,这是我在这一点上的最佳尝试。有些问题可能会改变回应:
// Adjust this line to simply GET the field for the doctor images
$doctor =rgar( $entry, 3 );
// Now, given the revision above, this line should properly explode the images
$doctorimage = explode( ',', $doctor );
// Adjust the below to put the images in (no need for rgar for them here)
$body = array(
'first name' => rgar( $entry, '1' ),
'last name' => rgar( $entry, '2' ),
'doctor source' => rgar( $entry, '3' ),
'doctor image1' => $doctorimage[0],
'doctor image2' => $doctorimage[1]
);
// Send the data to Google Spreadsheet via HTTP POST request
//....
可能有所作为的问题:
1.表格中的IS字段3是什么?根据您的代码,它是图像的两个网址 - 是吗?
2.表格中是否有字段4(和字段5)?它们包含什么?
3.您的表格中哪些字段应该是&#34;医生来源&#34;?