PHP 表单转换为 SharePoint 2010


PHP form into SharePoint 2010

这个想法听起来很简单:将输入到PHP表单(我们使用Drupal 7(中的数据提交到SharePoint 2010中。但是我在弄清楚它时遇到了一些问题。

每个表单条目都应在 SharePoint 中记录为一个项目,以便可以搜索和区分它们。所以我相信 SharePoint 列表或表单库会起作用。我只是缺乏使用SharePoint的经验,无法真正知道从哪里开始。

我想知道你认为这如何工作,如果有的话。

这当然可以工作,您需要在 SharePoint 中创建一个列表,其中包含存储表单数据所需的列。然后,从您的 PHP 代码中,您可以调用列表 Web 服务http://<site>/_vti_bin/Lists.asmx并使用 UpdateListItems 方法添加项目。

请查看 MSDN 文档列表 Web 服务、Lists.UpdateListItems 方法和如何:更新列表项,这些不使用 PHP,但您应该能够调整这些示例。

查询列表时,需要使用 CAML 为列表 Web 服务编写查询,请参阅此 SO 问题,了解一些有助于编写这些查询的工具。这些查询包装在发送到 Web 服务的SOAP信封中。

我不懂PHP,但下面的引用和代码来自David的IT博客 - 使用PHP创建SharePoint列表项

要使代码正常工作,您需要NuSOAP库,您自己的本地列表WSDL文件,当然还有下面的代码中您自己的个性化身份验证/列表变量。此代码已在 SharePoint Online 和 PHP 5.3 中进行了测试,但应该适用于 MOSS 2007。

<?php
// Requires the NuSOAP library
require_once('lib/nusoap.php');
$username = 'yourUsername';
$password = 'yourPassword';
$rowLimit = '150';
/* A string that contains either the display name or the GUID for the list.
 * It is recommended that you use the GUID, which must be surrounded by curly
 * braces ({}).
 */
$listName = "TempList";
/*
 * Example field (aka columns) names and values, that will be used in the
 * CAML query. The values are the attributes of a single list item here.
 * If the field name contains a space in SharePoint, replace it
 * here with _x0020_ (including underscores).
 */
$field1Name = "Title";
$field2Name = "Address";
$field3Name = "Premium_x0020_customer";
$field1Value = "John Smith";
$field2Value = "USA";
$field3Value = "1";
/* Local path to the Lists.asmx WSDL file (localhost). You must first download
 * it manually from your SharePoint site (which should be available at
 * yoursharepointsite.com/subsite/_vti_bin/Lists.asmx?WSDL)
 */
$wsdl = "http://localhost/phpsp/Lists.wsdl";
//Basic authentication is normally used when using a local copy a the WSDL. Using UTF-8 to allow special characters.
$client = new nusoap_client($wsdl, true);
$client->setCredentials($username,$password);
$client->soap_defencoding='UTF-8';
//CAML query (request), add extra Fields as necessary
$xml ="
 <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
 <listName>$listName</listName>
 <updates>
 <Batch ListVersion='1' OnError='Continue'>
 <Method Cmd='New' ID='1'>
 <Field Name='$field1Name'>$field1Value</Field>
 <Field Name='$field2Name'>$field2Value</Field>
 <Field Name='$field3Name'>$field3Value</Field>
 </Method>
 </Batch>
 </updates>
 </UpdateListItems>
";
//Invoke the Web Service
$result = $client->call('UpdateListItems', $xml);
//Error check
if(isset($fault)) {
 echo("<h2>Error</h2>". $fault);
}
//extracting the XML data from the SOAP response
$responseContent = utf8_decode(htmlspecialchars(substr($client->response,strpos($client->response, "<"),strlen($client->response)-1), ENT_QUOTES));
echo "<h2>Request</h2><pre>" . utf8_decode(htmlspecialchars($client->request, ENT_QUOTES)) . "</pre>";
echo "<h2>Response header</h2><pre>" . utf8_decode(htmlspecialchars(substr($client->response,0,strpos($client->response, "<")))) . "</pre>";
echo "<h2>Response content</h2><pre>".$responseContent."</pre>";
//Debugging info:
//echo("<h2>Debug</h2><pre>" . htmlspecialchars($client->debug_str, ENT_QUOTES) . "</pre>");
unset($client);
?>