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
- How can I process a form submission from an HTTP POST request?
- How to limit the number of forgot password reset attempts in WordPress?
- Fetch post block/field data as JSON with WordPress API
- Custom search results page not working with empty search
- WP grandchild categories in nested ul li
- Modify HTML structure of fields in woocommerce checkout form
- Use DOMDocument with ob_start breaks my HTML code
- How to change redirection route to a php page for making it only accessible by logged-in members?
- selected option if current category is the value
- Post + form + action + results on the same page
- Ajax call return 404
- How to remove ?wp-mce-4103-20162941
- wp_enqueue_script seperately for each shortcode
- Customize position of social icons in upme plugin [closed]
- How to pre populate a form field with a link of a current user’s author profile?
- parts of url disappear when using # inside href=”” [closed]
- database sent to a JSON file
- Settings API callback function inserts html quotes from nowhere
- How to insert HTML/JavaScript form into WordPress page? [closed]
- Different post styles depending on category
- How create a Shortcode with hover and complex options
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- Dot is not added at the end of href
- WordPress Multiple Navigation bars
- Position banner to right of logo in header – messed up my header file
- Commenting out unwated CSS/scripts in HTML with PHP
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- Show success or error messages in Ajax response to WordPress custom registration form
- Styling my own password protected page, how to deal with wrong password?
- Contact form won’t submit
- wp_mail file attachment not being placed in upload folder?
- Fetching instagram api not working on wordpress
- How to separate HTML and WordPress files
- Add .htm extention to a custom taxonomy
- Search Query: how to construct a search string from two select elements?
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Databases – Submitting data from inputs to database [closed]
- How to show a ‘correct’ message after submit a form?
- How do I add a custom css to all posts without affecting homepage css? [closed]
- db converts decimal number wrong
- Form Security: nonce vs. jQuery
- Make PHP work with HTML tags
- WordPress admin-ajax.php 400 bad request
- Noscript not working as it should in wordpress site
- Show latest posts in a plain HTML website custom widget [closed]
- How to convert select to HTML with PHP tags inside of it [closed]
- Is this spyware on my site or a real Java update?
- Syntax error when I try to insert my loop into an unordered list? [closed]
- Ajax contact form return 0
- Trying do build a contact form
- How to make modifications only to certain elements of an HTML string on the server-side?
- “operation successful” message
- Wrapping a Sidebar within
- JSON REST API WordPress only showing first 10 categories
- User register hook is not working in woocomerce register form
- Hide HTML element (by class or ID) with PHP
- Add Codepen animation as Preloader to WordPress
- Path for php file for inserting data through html form
- Function returns text instead of html [closed]
- Printing HTML codes
- Widget back end radio button issue
- HTML escaping data with ajax requests
- How i can get post data from database when i am getting post id from url in wordpress
- How to retrieve the data from the sever and displaying it in a page?
- php within html within php
- How to remove coupon dropdown feature
- Add data-id attribute to child page links
- Add shortcode in my div
- How to put a form with php code into a variable or shortcode?
- Can a page contain php code?
- WordPress plug-in for dynamic download link?
- HTML table attributes ignored
- How to send form data from WordPress (Meta Box) to an OData service?
- php esc_html_e with an html link inside not working
- Add html link in functions.php files of the theme
- Using ob_start and ob_get_clean with wordpress shortcode
- How to edit HTML of my website on WordPress? [closed]
- WordPress wp-admin redirect and exception
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- WordPress shortcode returns the data before