Input data from email form not going to JSON file

I have checked the code. file_put_contents function accepts the absolute path for the file. Use the ‘get_template_directory()’ function for the absolute path. Please check the updated code.

<form method="get"><p id="myform"><input type="email" name="EMAIL" placeholder="enter email address" required />
<input id="submit" name="submit" type="submit" value="Sign up" /></p></form>



if (isset($_POST['submit'])) {
$file = get_template_directory() . '/data.json';
$json_string = json_encode($_POST, JSON_PRETTY_PRINT);
file_put_contents($file, $json_string, FILE_APPEND);
}

Note: Code is writing all POST data into the json file. If you just want email address then change json_encode($_POST, JSON_PRETTY_PRINT); into json_encode($_POST['EMAIL'], JSON_PRETTY_PRINT);

Cheers 🙂