【问题标题】:PHP form into SharePoint 2010将 PHP 表单导入 SharePoint 2010
【发布时间】:2013-09-25 19:29:04
【问题描述】:

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

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

我想知道您认为这会如何奏效(如果有的话)。

【问题讨论】:

  • 恐怕不是 hakre,反之亦然。我不需要查询 SharePoint 的数据库。请删除不赞成票并重复。
  • 本网站要求您提前告知。显示哪些现有问答对您不起作用,并准确解释原因。在您的问题中,不仅仅是在 cmets 中,因为其他人确实进行了一些搜索。尤其是在给出的问答中谈到了双向访问,所以没有其他办法,除非你的意思是你根本不想与共享点交互;) - 我从来没有投反对票,尽管你的问题值得单独结束,因为你要求一个被认为离题的工具或资源。只是说。
  • 我了解这似乎是在尝试查询 SharePoint。但是对于能够回答这个问题的人,那些具有 SharePoint 经验的人,他们会按预期理解我的问题,并且看到它不是重复的。不需要向他们进一步解释。因此,我觉得这个问题是充分的,而不是重复。

标签: php xml sharepoint-2010 drupal-7


【解决方案1】:

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

查看 MSDN 文档 Lists Web ServiceLists.UpdateListItems MethodHow to: Update List Items,它们不使用 PHP,但您应该能够调整示例。

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

我不懂 PHP 但下面的引用和代码来自David's IT Blog - Creating SharePoint list items with PHP

要使代码正常工作,您需要 NuSOAP 库、您自己的本地 Lists 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);
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 2013-06-04
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多