I have an embedded interview (like a contact form) on WordPress, I use an on click function to set a text value of a div to the name of that interview's input field that has focus.
I have created a PHP plugin who's purpose is to get the name from WordPress and return a definition (hosted on a Notion database).
I do not know how to grab the value from that WordPress div on click (/value change) and pass it to the PHP plugin to use as a filter (key) so that I may be able to return the definition.
$databaseId = "BBB";
$url = "https://api.notion.com/v1/databases/$databaseId/query"; //api endpoint
$token = 'AAAA';
$version = '2021-08-16';
$contentType = "Content-type: application/json";
// value to be gotten from Wordpress
$dataElementName = $_REQUEST['q'];
// ADD INTEGRATION TO GET VALUE
//post data
$data_array =
['filter' =>
[
"property"=>"DataElement",
"title"=>["equals"=>$dataElementName]
]
];
$data = json_encode($data_array);
//intialize cURL
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//below is for posting
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Remove when push to wordpress
//auth header notionAPI
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token,
'Notion-Version: '.$version,$contentType));
//output
$resp = curl_exec($ch);
//error check
if($e = curl_error($ch))
{
echo $e;
} else
{
$decoded = json_decode($resp, true);
//var_dump($decoded);
//meaning will be passed to Javascript for Output
$meaning = $decoded['results'][0]['properties']['Meaning']['rich_text'][0]['text']['content'];
echo $meaning;
}
curl_close($ch);
Any advice is greatly appreciated.