我尝试通过他们的 API 将表单发布到 trello。
这是我的代码:
<?php
require_once '/src/Trello/trello.php';
$key = '[KEY]';
$token = '[TOKEN]';
$trello = new 'Trello'Trello($key, null, $token);
$title = $_POST['title'];
$desc = $_POST['content'];
$fileSource = $_POST['file'];
Trello->post("cards", { name: $title, desc: $desc, idList:"54f882603b3b0af795078283", pos: "top", fileSource: $file});
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<title>php form2trello</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script></script>
</head>
<body>
<div class="jumbotron">
<div class="container text-center">
<h1>php form2trello</h1>
</div>
</div>
<div class="container">
<div class="text-center">
<div class="row">
<div class="col-md-12">
<form id="trello" class="form-horizontal" method="post">
<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" required/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<textarea name="content" cols="40" rows="10" placeholder="Content" class="form-control" required></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">
<input class="btn btn-primary" type="submit" id="submit">
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
(出于安全目的,我删除了[密钥]和[令牌])
这是一个演示页面:http://area51.zoker.me/test/php/output/
正如您在一开始看到的,只有一个输出post("cards", { name: $title, desc: $desc, idList:"54f882603b3b0af795078283", pos: "top", fileSource: $file});?>
为什么 php 输出这些字符串?我怎样才能避免它这样做?
如果您检查链接的页面的源代码,似乎整个 php 代码都包含在 HTML 页面中,而不是被执行。因此,它将<?php
视为开始 html 标记,将Trello->
视为结束标记。其余部分作为普通 html 文本打印在页面中。
此外,有评论询问这是.html
/.htm
还是.php
页面。它看起来像一个.html
页面(我尝试了index.php
并得到了一个404
,尝试了index.html
并加载了它),因此 php 代码不会被解析。
将index.html
重命名为 index.php
,
此行
Trello->post("cards", { name: $title, desc: $desc, idList:"54f882603b3b0af795078283", pos: "top", fileSource: $file});
应该或多或少地读成这样:
$trello->post("cards", json_encode([ 'name'=> $title, 'desc' => $desc, 'idList' => "54f882603b3b0af795078283", 'pos' => "top", 'fileSource' => $file ]));