目前我正在尝试将osTicket表单嵌入到我的网站中,以便用户可以提交集成到我网站的票证。
我在网上发现了一个PHP脚本,并且在另一个线程的用户的帮助下,我已经开始工作了,所以当我在服务器上运行脚本时,它会打开一张票据,其中包含PHP脚本中编写的所有信息。我希望能够有一个HTML页面,它从HTML页面上的表单提交信息,以替换PHP脚本中的预设信息。
我首先要完成此操作,只需从默认的“提交票证”中复制相关文件即可。作为osTicket的一部分而来的页面。我在网络浏览器中查看了源代码,看到了与我下载文件并在文本编辑器中查看文件时不同的代码。
所以我使用的PHP脚本是:
<?php
# //Configuration: Enter the url and key.
# url => URL to api/tickets.json # e.g http://yourdomain.com/s#upport/api/tickets.json
# key => API's Key (see admin panel o#n how to generate a key)
#
$config = array(
'url'=>'support.sinergycraft.net/tickets/api/tickets.json',
'key'=>'C2621CFA3E5F94B5396003218952DA0D'
);
#pre-checks
function_exists('curl_version') or die('CURL support required');
#set timeout
set_time_limit(30);
#Sample data for the ticket
# See https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md for full list of variables and options that you can pass.
$data = array("alert" => "true",
"autorespond" => "true",
"source" => "API",
"name" => "Angry User",
"email" => "api@osticket.com",
"subject" => "Testing API 3",
"message" => "MESSAGE HERE"
);
#Convert the above array into json to POST to the API with curl below.
$data_string = json_encode($data);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200)
exit(0);
echo $result;
exit(1);
?>
如果我将表单链接到此代码,就像我在此代码中所做的那样:
<form id="ticketForm" method="post" action="new_ticket.php" enctype="multipart/form-data">
PHP脚本名为new_ticket.php
。这将打开一张带有PHP中预填充选项的票证,但不会打开表单中输入的内容。
接下来我认为我应该尝试使用从服务器上下载的文件而不是我从视图源获取的代码。
单击链接以创建新票证时在浏览器中打开的文件称为open.php
,其内容如下:
<?php
open.php
require('client.inc.php');
define('SOURCE','Web'); //Ticket source.
$ticket = null;
$errors=array();
if ($_POST) {
$vars = $_POST;
$vars['deptId']=$vars['emailId']=0; //Just Making sure we don't accept crap...only topicId is expected.
if ($thisclient) {
$vars['uid']=$thisclient->getId();
} elseif($cfg->isCaptchaEnabled()) {
if(!$_POST['captcha'])
$errors['captcha']=__('Enter text shown on the image');
elseif(strcmp($_SESSION['captcha'], md5(strtoupper($_POST['captcha']))))
$errors['captcha']=__('Invalid - try again!');
}
$tform = TicketForm::objects()->one()->getForm($vars);
$messageField = $tform->getField('message');
$attachments = $messageField->getWidget()->getAttachments();
if (!$errors && $messageField->isAttachmentsEnabled())
$vars['cannedattachments'] = $attachments->getClean();
// Drop the draft.. If there are validation errors, the content
// submitted will be displayed back to the user
Draft::deleteForNamespace('ticket.client.'.substr(session_id(), -12));
//Ticket::create...checks for errors..
if(($ticket=Ticket::create($vars, $errors, SOURCE))){
$msg=__('Support ticket request created');
// Drop session-backed form data
unset($_SESSION[':form-data']);
//Logged in...simply view the newly created ticket.
if($thisclient && $thisclient->isValid()) {
session_write_close();
session_regenerate_id();
@header('Location: tickets.php?id='.$ticket->getId());
}
}else{
$errors['err']=$errors['err']?$errors['err']:__('Unable to create a ticket. Please correct errors below and try again!');
}
}
//page
$nav->setActiveNav('new');
if ($cfg->isClientLoginRequired()) {
if (!$thisclient) {
require_once 'secure.inc.php';
}
elseif ($thisclient->isGuest()) {
require_once 'login.php';
exit();
}
}
require(CLIENTINC_DIR.'header.inc.php');
if($ticket
&& (
(($topic = $ticket->getTopic()) && ($page = $topic->getPage()))
|| ($page = $cfg->getThankYouPage())
)) {
// Thank the user and promise speedy resolution!
echo Format::viewableImages($ticket->replaceVars($page->getBody()));
}
else {
require(CLIENTINC_DIR.'open.inc.php');
}
require(CLIENTINC_DIR.'footer.inc.php');
?>
我尝试将此替换为HTML代码中的操作,而不是new_ticket.php
,但我仍然没有运气。
所以基本上我要做的就是能够在HTML表单中提交信息,并用它替换PHP脚本中预先写好的文本,以便用户输入。
最后,下面我提供了open.php文件在浏览器中显示的内容,当我在Web浏览器中打开它时。这是我为我的HTML文档提供表格的文件,我希望将该数据提交给PHP脚本。
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>SinergyCraft.net Support</title>
<meta name="description" content="customer support platform">
<meta name="keywords" content="osTicket, Customer support system, support ticket system">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="/tickets/css/osticket.css?ecb4f89" media="screen">
<link rel="stylesheet" href="/tickets/assets/default/css/theme.css?ecb4f89" media="screen">
<link rel="stylesheet" href="/tickets/assets/default/css/print.css?ecb4f89" media="print">
<link rel="stylesheet" href="/tickets/scp/css/typeahead.css"
media="screen" />
<link type="text/css" href="/tickets/css/ui-lightness/jquery-ui-1.10.3.custom.min.css"
rel="stylesheet" media="screen" />
<link rel="stylesheet" href="/tickets/css/thread.css?ecb4f89" media="screen">
<link rel="stylesheet" href="/tickets/css/redactor.css?ecb4f89" media="screen">
<link type="text/css" rel="stylesheet" href="/tickets/css/font-awesome.min.css?ecb4f89">
<link type="text/css" rel="stylesheet" href="/tickets/css/flags.css?ecb4f89">
<link type="text/css" rel="stylesheet" href="/tickets/css/rtl.css?ecb4f89"/>
<script type="text/javascript" src="/tickets/js/jquery-1.8.3.min.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/jquery-ui-1.10.3.custom.min.js?ecb4f89"></script>
<script src="/tickets/js/osticket.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/filedrop.field.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/jquery.multiselect.min.js?ecb4f89"></script>
<script src="/tickets/scp/js/bootstrap-typeahead.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/redactor.min.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/redactor-osticket.js?ecb4f89"></script>
<script type="text/javascript" src="/tickets/js/redactor-fonts.js?ecb4f89"></script>
<meta name="csrf_token" content="4f5df4c017ca804903b7b513210231cd8fd6d714" />
</head>
<body>
<div id="container">
<div id="header">
<a class="pull-left" id="logo" href="/tickets/index.php"
title="Support Center"><img src="/tickets/logo.php" border=0 alt="SinergyCraft.net Support"
style="height: 5em"></a>
<div class="pull-right flush-right">
<p>
</p>
<p>
</p>
</div>
</div>
<div class="clear"></div>
<ul id="nav" class="flush-left">
<li><a class=" home" href="/tickets/index.php">Support Center Home</a></li>
<li><a class="active new" href="/tickets/open.php">Open a New Ticket</a></li>
<li><a class=" status" href="/tickets/view.php">Check Ticket Status</a></li>
</ul>
<div id="content">
<h1>Open a New Ticket</h1>
<p>Please fill in the form below to open a new ticket.</p>
<form id="ticketForm" method="post" action="open.php" enctype="multipart/form-data">
<input type="hidden" name="__CSRFToken__" value="4f5df4c017ca804903b7b513210231cd8fd6d714" /> <input type="hidden" name="a" value="open">
<table width="800" cellpadding="1" cellspacing="0" border="0">
<tbody>
<tr>
<td class="required">Help Topic:</td>
<td>
<select id="topicId" name="topicId" onchange="javascript:
var data = $(':input[name]', '#dynamic-form').serialize();
$.ajax(
'ajax.php/form/help-topic/' + this.value,
{
data: data,
dataType: 'json',
success: function(json) {
$('#dynamic-form').empty().append(json.html);
$(document.head).append(json.media);
}
});">
<option value="" selected="selected">— Select a Help Topic —</option>
<option value="12" >Ban Site/Server</option><option value="1" >General Inquiry</option><option value="2" >Recruitment</option><option value="10" >Report a Problem</option><option value="11" >White List Me</option> </select>
<font class="error">* </font>
</td>
</tr>
<tr><td colspan="2"><hr />
<div class="form-header" style="margin-bottom:0.5em">
<h3>Contact Information</h3>
<em></em>
</div>
</td></tr>
<tr>
<td><label for="b695be87472f918f" class="required">
Email Address:</label></td><td>
<span style="display:inline-block">
<input type="text"
id="_b695be87472f918f"
size="40" maxlength="64" placeholder="" name="b695be87472f918f"
value=""/>
</span>
<font class="error">*</font>
</td>
</tr>
<tr>
<td><label for="e6ac2c5b0fbeba20" class="required">
Full Name:</label></td><td>
<span style="display:inline-block">
<input type="text"
id="_e6ac2c5b0fbeba20"
size="40" maxlength="64" placeholder="" name="e6ac2c5b0fbeba20"
value=""/>
</span>
<font class="error">*</font>
</td>
</tr>
</tbody>
<tbody id="dynamic-form">
</tbody>
<tbody> <tr><td colspan="2"><hr />
<div class="form-header" style="margin-bottom:0.5em">
<link rel="stylesheet" type="text/css" href="/tickets/css/jquery.multiselect.css"/> <h3>Ticket Details</h3>
<em>Please Describe Your Issue</em>
</div>
</td></tr>
<tr>
<td><label for="48b638e54863b978" class="required">
Issue Summary:</label></td><td>
<span style="display:inline-block">
<input type="text"
id="_48b638e54863b978"
size="40" maxlength="50" placeholder="" name="48b638e54863b978"
value=""/>
</span>
<font class="error">*</font>
</td>
</tr>
<tr>
<td colspan="2">
<div style="margin-bottom:0.5em;margin-top:0.5em"><strong>Issue Details</strong>:</div>
<textarea style="width:100%;" name="message"
placeholder="Details on the reason(s) for opening the ticket."
data-draft-namespace="ticket.client"
data-draft-object-id="ea999hv0kkq1"
class="richtext draft draft-delete ifhtml"
cols="21" rows="8" style="width:80%;"></textarea>
<div id="b6d716e83936ea511681b5" class="filedrop"><div class="files"></div>
<div class="dropzone"><i class="icon-upload"></i>
Drop files here or <a href="#" class="manual"> choose them </a> <input type="file" multiple="multiple"
id="file-b6d716e83936ea511681b5" style="display:none;"
accept=""/>
</div></div>
<script type="text/javascript">
$(function(){$('#b6d716e83936ea511681b5 .dropzone').filedropbox({
url: 'ajax.php/form/upload/attach',
link: $('#b6d716e83936ea511681b5').find('a.manual'),
paramname: 'upload[]',
fallback_id: 'file-b6d716e83936ea511681b5',
allowedfileextensions: [],
allowedfiletypes: [],
maxfiles: 20,
maxfilesize: 32,
name: 'attach:21[]',
files: [] });});
</script>
<link rel="stylesheet" type="text/css" href="/tickets/css/filedrop.css"/> <font class="error">*</font>
</td>
</tr>
</tbody>
<tbody>
<tr><td colspan=2> </td></tr>
</tbody>
</table>
<hr/>
<p style="text-align:center;">
<input type="submit" value="Create Ticket">
<input type="reset" name="reset" value="Reset">
<input type="button" name="cancel" value="Cancel" onclick="javascript:
$('.richtext').each(function() {
var redactor = $(this).data('redactor');
if (redactor && redactor.opts.draftDelete)
redactor.deleteDraft();
});
window.location.href='index.php';">
</p>
</form>
</div>
</div>
<div id="footer">
<p>Copyright © 2015 SinergyCraft.net Support - All rights reserved.</p>
<a id="poweredBy" href="http://osticket.com" target="_blank">Helpdesk software - powered by osTicket</a>
</div>
<div id="overlay"></div>
<div id="loading">
<h4>Please Wait!</h4>
<p>Please wait... it will take a second!</p>
</div>
</body>
</html>
由于
答案 0 :(得分:0)
我可能会在你的问题中遗漏一些内容,但我认为你只需要在表单中添加更多内容然后在PHP中提取变量:
HTML:
<form id="ticketForm" method="post" action="new_ticket.php" >
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="subject" />
<textarea name="message"></textarea>
<input type="submit" name="submit" value="send" />
(我想我可以在你的页面源转储中看到一些这些输入字段,但是名称字段似乎是生成的,例如name="b695be87472f918f"
,无论你使用哪个html名称=&#39; name < / em>&#39;以及$ _POST [&#39; 名称&#39;]需要匹配)。
然后在您的PHP代码中:
$data = array("alert" => "true",
"autorespond" => "true",
"source" => "API",
"name" => $_POST['name'],
"email" => $_POST['email'],
"subject" => $_POST['subject'],
"message" => $_POST['message']
);
在实际使用它们之前对值进行一些验证可能是明智的。