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 🙂
Related Posts:
- add_filter the_content str_replace after shortcode
- Upload Image in a WordPress page using PHP
- woocommerce registration form with klaviyo(don’t work with current user)
- My form action url is being prepended with a directory that does not exists
- How to store data from multiple forms using ajax and php
- Why Won’t My Inputs in a form with a Get method work together?
- How to get the value of input hidden html from text editor to custom page template?
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Search WordPress using static html page
- How to execute html code inside php?
- How to add post meta in while loop?
- Adding attribute to the post.php form tag in wp-admin
- WordPressUser Submission Form
- Custom forms with HTML
- Cascading dropdown select search based on Parent Page & Child Page
- HTML Form Question
- wordpress form action page not found
- Can’t get_users info by using json_encode
- Custom HTML form using PHP – help with ajax/username validation
- How to enqueue structured data as file – jsonld file seems not to work
- navigate back with PHP form submission
- How do I make an HTML table from a database table?
- How to get the custom header image’s alt text?
- Modify previous and next text from pagination links
- How to correctly submit a search form and display the result in an independent page
- Correct regex for wp_embed_register_handler
- Metabox repeating fields – radio buttons not saving correctly
- WordPress custom taxonomy description for each post?
- How to handle a custom form in wordpress to submit to another page?
- Calling a method from functions.php on a click of a button
- Passing JSON data from WP Query into AJAX causing NULL errors
- Creating a WordPress form with a PHP script and default header
- Two posts in same div – WP loop
- How Do I Add User Custom Field to REST API Response?
- How to add a post or page tag to the list of classes appearing in the body tag’s class attribute?
- Getting the dropdown menu to redirect to different pages?
- To echo or not to echo?
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- Correct syntax to html php conversion
- Adding Custom Forms
- How do I let users upload files to a chosen location?
- ACF page while loop breaks footer while loop
- Getting a specific post values to another div or modal
- Creating a Multi-Level Associative Object Using AJAX
- search and replace preword from author
- How to limit the number of forgot password reset attempts in WordPress?
- WP grandchild categories in nested ul li
- Modify HTML structure of fields in woocommerce checkout form
- Customize position of social icons in upme plugin [closed]
- database sent to a JSON file
- Settings API callback function inserts html quotes from nowhere
- Position banner to right of logo in header – messed up my header file
- How to separate HTML and WordPress files
- Syntax error when I try to insert my loop into an unordered list? [closed]
- How to make modifications only to certain elements of an HTML string on the server-side?
- Printing HTML codes
- How to retrieve the data from the sever and displaying it in a page?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- wp_insert_post() with HTML tags using PHP
- Remove   from the_excerpt
- PHP Contact form
- Adding Additional Variables on Menus Page
- form $_post action value gets truncated after it passes through two forms
- What should I write in the post action of this front end post form?
- Contact form – problem with displaying message about sent mail
- html form: redirect page after form completes submit function and posts data
- WordPress Post Block Element not properly parsed with the_content filter
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Add other class content with reference class value
- Configure WordPress to Use Responsive Image Rendering
- Form from within a page
- HTML comment cause issue in functions.php script root
- Slug duplicates once clicking on link
- I want to retrieve the email or username data entered for password reset, but failed. how can I do it?
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Remove span tags from WooCommerce Downloads page
- How to find and delete a menu item in php?
- My single.php page skips the first div tag
- opens like sitename.com/URL
- WordPress Slider is not working
- How to display post meta bellow every posts
- form submission reverts to index.php template
- Access certain Entry in HTML-Table and pass the entry-data in WP not working [closed]
- Switch position of elements in the footer [closed]
- scroll scrpit to particular button position to next id when click button
- Adding action item to admin users table and sending email
- Passed variable gets undefined variable error on insert on next page
- How to set up an auto delete post?
- WordPress HTML Helper
- get_post_meta is always empty when I use wp_mail
- Display default WordPress login/registration form into a modal window
- ajax form function error
- Send foreach $_post method to contact form 7 [closed]
- Implement “No related posts for this entry” into the loop?
- ACF repeater image in video poster with jquery
- Advanced Custom Fields Show PHP in Text Areas
- Use HTML Form Data in PHP Function – WordPress Admin Page
- Contact form with dynamic dropdown and filter
- Add multiple HTML attributes to an Elementor button
- Saving meta box data from selected option’s value in database is not working