Skip to content

Instantly share code, notes, and snippets.

@Arood
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arood/92046dca9434ef798cfe to your computer and use it in GitHub Desktop.
Save Arood/92046dca9434ef798cfe to your computer and use it in GitHub Desktop.
Send form data to Jira issue as comment
<?php
$username = 'xxx';
$password = 'xxx';
$host = 'http://xxx';
$issue = 'KEY-000';
if (count($_POST) > 0) {
$body = "";
foreach ($_POST as $field => $value) {
$body .= "*$field*:\n".$value."\n\n";
}
$body = json_encode(array("body" => $body));
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $host.'/rest/api/2/issue/'.$issue.'/comment');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($body))
);
$result = (curl_exec($curl));
header("Location: ?thanks");
die;
//echo $result;
}
?><!DOCTYPE html>
<html>
<head>
<title>Testrapport</title>
<style>
@import url(http://fonts.googleapis.com/css?family=Raleway:400,700);
body {
font: 15px/27px Raleway, sans-serif;
padding: 50px 75px 75px;
margin: 0;
}
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
form {
margin: 0 auto;
max-width: 600px;
}
form:after {
content: "";
display: table;
clear: both;
}
label {
color: #aaa;
margin: 25px 0 0px;
display: block;
font-size: 11px;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
-webkit-appearance: none;
}
input[type="text"], textarea {
border: 0;
border-bottom: 1px solid #ccc;
padding: 10px 0;
font: 16px/28px Raleway, sans-serif;
width: 100%;
margin: 0;
outline: none;
}
input[type="text"]:focus, textarea:focus {
border-bottom-color: #000;
}
button {
font: 16px/28px Raleway, sans-serif;
cursor: pointer;
padding: 5px 10px;
border: 0;
margin: 25px 0 0;
border-radius: 6px;
background: #599BD9;
color: #fff;
padding: 10px 25px;
float: right;
-webkit-appearance: none;
}
button:hover {
background: #377DC0;
}
::-webkit-input-placeholder { /* WebKit browsers */
font: 16px/28px Raleway, sans-serif;
color: #aaa;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
font: 16px/28px Raleway, sans-serif;
color: #aaa;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
font: 16px/28px Raleway, sans-serif;
color: #aaa;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
font: 16px/28px Raleway, sans-serif;
color: #aaa;
}
</style>
</head>
<body>
<form method="post" action="">
<?php
if (isset($_GET['thanks'])) {
echo '<h2>Tack för din medverkan!</h2><p>Skicka en till rapport?</p>';
}
?>
<label>Ditt namn</label>
<input id="name" name="Name" type="text" placeholder="Anna Andersson" />
<label>Enhet</label>
<input id="device" name="Device" type="text" placeholder="Ex. iPhone 5C / LG Nexus 5" />
<label>Operativ-system</label>
<input id="os" name="OS" type="text" placeholder="iOS 7.1.3 / Android 4.1" />
<label>Beskrivning</label>
<textarea id="desc" name="Description" rows="1" placeholder="Kort beskrivning av din rapport"></textarea>
<label>Steg för att återskapa</label>
<textarea id="reproduce" name="Reproduce" rows="1" placeholder="Skriv gärna som punktlista"></textarea>
<label>Förväntat resultat</label>
<textarea id="expected" name="Expected" rows="1" placeholder="Vad trodde du skulle hända?"></textarea>
<label>Faktiskt resultat</label>
<textarea id="actual" name="Actual" rows="1" placeholder="Vad hände istället?"></textarea>
<button type="submit">Skicka</button>
</form>
<script>
var observe;
if (window.attachEvent) {
observe = function (element, event, handler) {
element.attachEvent('on'+event, handler);
};
}
else {
observe = function (element, event, handler) {
element.addEventListener(event, handler, false);
};
}
var initTextarea = function(text) {
function resize () {
text.style.height = 'auto';
text.style.height = (text.scrollHeight+1)+'px';
}
function delayedResize () {
window.setTimeout(resize, 0);
}
observe(text, 'change', resize);
observe(text, 'cut', delayedResize);
observe(text, 'paste', delayedResize);
observe(text, 'drop', delayedResize);
observe(text, 'keydown', delayedResize);
text.focus();
text.select();
resize();
}
function init () {
var textareas = document.querySelectorAll("textarea");
for (var i=0; i<textareas.length; i++) {
initTextarea(textareas[i]);
}
}
init();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment