I'm making a theme wordpress use childtheme in localhost. I had a basic form html in footer.php
:
<form method="post">
<input name="FNAME" type="text">
<input name="LNAME" type="text">
<input name="EMAIL" type="email">
<button type="submit">Subscribe</button>
</form>
Now , I want to submit form to an api url via cURL php. I know code to set up cURL like this:
$data = $_POST;
$curl = curl_init();
$options =array(
CURLOPT_RETURNTRANSFER =>true,
CURLOPT_URL => 'link_to_url',
CURLOPT_POST => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POSTFIELDS => http_build_query($data)
);
curl_setopt_array($curl, $options);
$result = curl_exec($curl);
curl_close($curl);
I want to when form is submitted , POST data will send via this cURL, But I don't know where I should place this code and how to process it. I think it maybe placed in a function in function.php
but I don't know how to write it .Please help me!