通过 html 表单添加 trello 卡片
Add trello card via html form
我对 api 很陌生,想做以下事情:
Post 使用我页面上的表单将新卡片添加到 trello 看板。
Trello 提供了 api,但我真的不知道如何使用它:
http://mattzuba.bitbucket.org/php-trello/
我的表单如下所示:
<form id="trello" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="Name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="eMail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="Title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="file" name="attachment" value="1" class="form-control">
</div>
</div>
<div class="form-group">
<a class="btn btn-primary" id="submit">Submit</a>
</div>
</form>
现在我想创建一张如下所示的卡片:
card-name: $title
card-content: $content
Submitted by: $name ($email)
card-attachment: $attachment
因为这个表单应该是 public(带有验证码),oAuth 对我来说没有办法:/
我不知道如何存档:/
如果有人给我一个例子,那就太棒了:)
有人可以帮我吗?
我整理了以下代码,对我有用。
<?php
if ($_POST) {
$card_name = htmlspecialchars($_POST['title']);
$card_content = htmlspecialchars($_POST['content']) . "\n";
$card_content .= htmlspecialchars($_POST['name']) . " (" . htmlspecialchars($_POST['email']) . ")";
$trello_key = 'YourTrelloApiKey';
$trello_api_endpoint = 'https://api.trello.com/1';
$trello_list_id = 'IdOfListYouArePostingTo';
$trello_member_token = 'AnApplicationTokenYouHaveGenerated'; // Guard this well
$url = 'https://api.trello.com/1/cards';
$fields='token='.$trello_member_token;
$fields.='&key='.$trello_key;
$fields.='&idList='.$trello_list_id;
$fields.='&name='.$card_name;
$fields.='&desc='.$card_content;
$result = trello_post($url, $fields);
}
function trello_post($url, $fields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
?>
<form id="trello" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="E-Mail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<input type="submit" value="Submit">
</div>
</form>
我唯一没有处理的是附件上传。支持这一点的文档很少。
我对 api 很陌生,想做以下事情: Post 使用我页面上的表单将新卡片添加到 trello 看板。 Trello 提供了 api,但我真的不知道如何使用它: http://mattzuba.bitbucket.org/php-trello/
我的表单如下所示:
<form id="trello" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="Name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="eMail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="Title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="file" name="attachment" value="1" class="form-control">
</div>
</div>
<div class="form-group">
<a class="btn btn-primary" id="submit">Submit</a>
</div>
</form>
现在我想创建一张如下所示的卡片:
card-name: $title
card-content: $content
Submitted by: $name ($email)
card-attachment: $attachment
因为这个表单应该是 public(带有验证码),oAuth 对我来说没有办法:/
我不知道如何存档:/ 如果有人给我一个例子,那就太棒了:)
有人可以帮我吗?
我整理了以下代码,对我有用。
<?php
if ($_POST) {
$card_name = htmlspecialchars($_POST['title']);
$card_content = htmlspecialchars($_POST['content']) . "\n";
$card_content .= htmlspecialchars($_POST['name']) . " (" . htmlspecialchars($_POST['email']) . ")";
$trello_key = 'YourTrelloApiKey';
$trello_api_endpoint = 'https://api.trello.com/1';
$trello_list_id = 'IdOfListYouArePostingTo';
$trello_member_token = 'AnApplicationTokenYouHaveGenerated'; // Guard this well
$url = 'https://api.trello.com/1/cards';
$fields='token='.$trello_member_token;
$fields.='&key='.$trello_key;
$fields.='&idList='.$trello_list_id;
$fields.='&name='.$card_name;
$fields.='&desc='.$card_content;
$result = trello_post($url, $fields);
}
function trello_post($url, $fields){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
?>
<form id="trello" method="post" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input type="text" name="name" placeholder="Name" class="form-control" />
</div>
<div class="col-md-6">
<input type="email" name="email" placeholder="E-Mail" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="text" name="title" placeholder="Title" class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<input type="submit" value="Submit">
</div>
</form>
我唯一没有处理的是附件上传。支持这一点的文档很少。