I have this sample of API code, i'm trying to embed my form into it. This code is in php. Below is the sample API code
-----------------------------------------------------------------------------------
<?php
echo(get_sentiment_rank_text("We like sharing our service with you. We hope you enjoy it as well."));
function get_sentiment_rank_text($content) {
//get the sentiment scoring info
$result = get_sentiment($content);
$jsonarray = json_decode($result);//get results as json object
$sentiment_rank = $jsonarray->sentiment->summary->sentiment_rank;//get values from json object
return $sentiment_rank;
}
function get_sentiment($phrase) {
//create array of data to be posted
$phrase = html_entity_decode(strip_tags($phrase)); //strip any HTML tags and decode the scring
$phrase = preg_replace('/[\n\r\t]/',' ',$phrase); //replace newlines and tabs
$phrase = preg_replace('/ /',' ',$phrase); //
$phrase = preg_replace( '/\s+/', ' ', $phrase );//remove multiple white spaces
$phrase = urlencode($phrase);
$post_data['app_key'] = '[API_KEY]';
$post_data['phrase'] = $phrase;
//$post_data['callback'] = 'myFunction';
$post_data['format'] = 'json';
//$post_data['ref'] = 'ABC123';
$post_data['showoveralltext'] = 'false';
$post_data['showsummarybreakdown'] = 'false';
$post_data['showsentencetext'] = 'false';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection = curl_init('http://api.sentirate.com/sentiment/request.do');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
// curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
return $result;//String that is a JSON String - i.e. resultant web page
}
?>
-----------------------------------------------------------------------------------------------------------------
and this is my form, is just a simple form
-----------------------------------------------------------------------------------------------------------------
</head>
<body>
<form name="Senti form" method="POST" action="">
<textarea name = "ftext" rows = "10" cols = "50"></textarea>
<br>
<input type="submit" value="send" name ="btn1">
<br>
</body>
i would be glad if anyone hear can guide me to embed the code.
Thanks