我尝试通过他们的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>
(出于安全目的,我删除了[KEY]和[TOKEN])
这是一个演示页面: http://area51.zoker.me/test/php/output/
正如您在一开始所看到的,只有输出post("cards", { name: $title, desc: $desc, idList:"54f882603b3b0af795078283", pos: "top", fileSource: $file});?>
为什么php输出这些字符串? 我怎么能避免这样做呢?
答案 0 :(得分:3)
如果您检查链接的页面的来源,则看起来整个PHP代码都包含在HTML页面中,而不是被执行。因此,它将<?php
视为开始的html标记,将Trello->
视为结束标记。其余的作为普通的html文本打印在页面中。
此外,评论询问这是.html
/ .htm
还是.php
页面。它看起来像.html
页面(我尝试了index.php
并得到了404
,尝试使用index.html
加载了它,因此php代码无法解析
答案 1 :(得分:1)
将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 ]));