admin管理员组文章数量:1419186
everyone!
I'm pretty new to wordpress development, and right now i'm trying develop a small ecommerce site using some wordpress plugins and some php on my part.
Right now i'm in the middle of developing a feedback page to pass on to freshdesk using API.
I tried it on localhost, and it's working. Freshdesk receives the ticket and everything, but when I do it in wordpress, it's not passing on the data.
Here's the simple post method using forms
<div class="feedback-form">
<form action="includes/feedback.inc.php" method="POST">
<font class="fdeskfont">Full Name</font>
<br>
<input type="text" name="fullname">
<p></p>
<font class="fdeskfont">Email</font>
<br>
<input type="text" name="email">
<p></p>
<font class="fdeskfont">Subject</font>
<br>
<input type="text" name="subject">
<p></p>
<font class="fdeskfont">Message</font>
<br>
<textarea type="text" name="description"></textarea>
<p></p>
<button type="submit" name="submit">Submit</button>
</form>
</div>
And here's the include:
$api_key = "API_KEY";
$password = "MY_PASSWORD";
$yourdomain = "";
$custom_fields = array("cf_full_name" => "Sample_Name");
$ticket_data = json_encode(array(
"description" => "Some details on the issue ...",
"subject" => "Support needed..",
"email" => "[email protected]",
"custom_fields" => $custom_fields,
"priority" => 1,
"status" => 2,
));
$url = "https://MY_DOMAIN/api/v2/tickets";
$ch = curl_init($url);
$header[] = "Content-type: application/json";
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $ticket_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($server_output, 0, $header_size);
$response = substr($server_output, $header_size);
if($info['http_code'] == 201) {
echo "Ticket created successfully, the response is given below \n";
echo "Response Headers are \n";
echo $headers."\n";
echo "Response Body \n";
echo "$response \n";
} else {
if($info['http_code'] == 404) {
echo "Error, Please check the end point \n";
} else {
echo "Error, HTTP Status Code : " . $info['http_code'] . "\n";
echo "Headers are ".$headers;
echo "Response are ".$response;
}
}
curl_close($ch);
Btw, I'm using a child theme and a custom page I added to access the include. How do I fix this?
Child theme/custompage/include
本文标签: phpHow to use POST method using custom wordpress button
版权声明:本文标题:php - How to use POST method using custom wordpress button? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745306226a2652660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论