Я пытаюсь отправить форму в trello через их api.
Это мой код:
<?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 выводит эти строки? Как я могу избежать этого?
Если вы проверяете источник связанной вами страницы, то кажется, что весь 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 ]));