I have not used Curl much in the past and am getting a bit confused.
I am trying to grab the info in my form and post to the URL set in my CURLOPT_URL
.
I can get the basic Json to post in postman using the following
{
"type":"bio",
"title":"new test5"
}
but when i try and add the data from my html form it dose not work, I think I have gone a bit wrong could someone correct me and let me know what I havedone wrong, thanks.
Full Code
<form method = 'POST'>
<div class="">
<label><b>Title</b></label>
<input type="text" placeholder="Enter Title" name="titletext" required>
<button type="submit">Send</button>
</div>
</form>
<?php
$curl = curl_init();
if(isset($_POST['titletext']))
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/communicator-app/bensapi/node/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array
(
'type' => 'bio',
'title' => $_POST['titletext']
),
CURLOPT_COOKIE => file_get_contents( 'session_cookie.txt' ),
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo "POSTED !";
}