You should never access directly theme files, form submissions, ajax, and even just get requests will be blocked at the server level by some security hardening measure.
Ignoring that for a moment, the reason your code fails is because wordpress wasn’t bootstrapped and therefor there are no core functions available. It is actually not 100% fail safe process to find from a theme file where the wordpress files are installed in order to bootstrap it which is yet another reason not to attempt to do access theme files directly.
You need to decide on a “normal” wordpress url to submit to the form (the post in which the pos is?), and probably intercept it on the init hook, or use ajax and write the appropriate ajax hooks and handlers.
Related Posts:
- jQuery’s .on() method combined with the submit event
- Nonces and Cache
- How to HTML5 FormData Ajax
- admin-ajax.php doesn’t work when using POST data and Axios
- Contact Form 7 Custom Post Action
- Custom Form with Ajax
- ajax – why multiple calls to wp_create_nonce() return same value?
- How to link WordPress heartbeat to ajax form
- Ajax form submission from admin panel
- Confused on AJAX submit form through page template
- how to use reCaptcha v3 in wordpress custom login form?
- Prevent page reload after ajax form submission
- How to make get_theme_mod work with AJAX in the customizer preview
- submitting form via admin-ajax.php returns 0
- Admin Ajax and HTML5 Formdata
- jQuery Ajax passing empty parameters to my function?
- Using ajax with wordpress
- Using AJAX with Forms
- Ajax image upload with media_handle_upload and form.js
- Ajax post returning full html page as response
- Sending variable from ajax on form submit
- contact form ajax empty response error message
- Can’t trigger an AJAX function with a submit button in the dashboard
- Dynamically add more fields/remove last field in a form
- Ajaxify Form That Submits To Same Page To Display Post Data [closed]
- Using admin-ajax prevents regular php form submission
- Specify ABSPATH in jQuery url
- ajax form is returning the dreaded “[HTTP/1.1 400 Bad Request” and a zero
- Output multi-steps form results in same page
- How to create a form button that executes a function?
- How to stop being directed to admin.php after sending request to admin-ajax.php
- How to display contact form 7 form in vanilla js without jquery in frontend
- Should wordpress nonce be placed in html form or in javascript file
- Add Server Side validation in Ajax mail form
- How to send automatic response after form submission without plugin
- Opening Modal popup on Ajax form submission
- Registration form AJAX check for existing username (simple version)
- Issue developing an AJAX form with WordPress
- Ajax show custom post data form & script
- Using AJAX on Contact-form the WordPress way
- Error while submitting form using AJAX and php
- Ajax contact form returnig 0
- Ajax Form data is not posted back to the get_results()
- Using AJAX for dynamic settings pages
- Ajax Form seems to post, but does not return
- Bad Request when adding new post via ajax form
- WordPress REST API FormData: Form Not Submitted When No Files Attached
- Using Ajax with a Class file
- Displaying PHP Errors from admin-ajax.php
- wp_set_auth_cookie() doesn’t work in Ajax call
- Stop admin-ajax?
- Is it safe to assume that a nonce may be validated more than once?
- store/cache ajax sent data to avoid repeated request
- Insert Post using Ajax
- How can I automatically login using a URL?
- Run again current query via ajax but changing a var
- Quick Edit: Selected Custom Taxonomy Not Refreshing After Save
- wp_verify_nonce always returns false when logged in as admin
- fetching via fetch/ajax gutenberg block data from third party
- Ajax requests with different WordPress Address and Site Address setup
- How to check an ajax nonce in PHP
- admin-ajax.php slows down, but cant figure out which plugin
- Convert this relative path to absolute
- Load WP content with ajax less server demanding and faster than normal page loading?
- admin-ajax.php slow website, how to fix
- WP Admin AJAX Security – using POST to include a relative URL
- Admin-ajax.php 400 error
- AJAX Load more on CPT returning random posts
- WordPress admin-ajax.php not available for subscribers/contributors
- get_queried_object_id in AJAX
- Should I check for privileges before hooking into `wp_ajax_$handle` or after?
- Ajax fail and get 504 error
- Images loading over http instead of https
- Show success or error messages in Ajax response to WordPress custom registration form
- Ajax login without redirect/reload
- wp_mail 200 response but no mail sent
- Is it secure to use admin-ajax.php in front?
- Best way to use ajax front-end?
- Ajax calls from the theme directory
- How to pass parameters from jQuery ajax into PHP function?
- use jQuery.load() to include a php file in a div, wp_query() is part of php file
- WordPress function not defined in AJAX call
- Fetch value using AJAX in WordPress
- Can I use application/json content type in WordPress
- What is the relationship between UFW (firewall) being enabled and cron job running?
- WPBakery post content inside Bootstrap Modal
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- Hook after all metadata are set is triggering several time
- check_ajax_reffer not working when logged
- Assign author on ajax wp post insert
- Portfolio list view after clicking back button
- How to use add_action(‘wp_ajax_[action name]’,…) for a specific page with condition?
- AJAX save options inside class
- How to test if in dashboard, bypassing Ajax quirk
- Usage of wp_send_json_success and wp_redirect at the same time
- Can I make an ajax response cross-domain?
- update_user_meta updates to a wrong ID
- WordPress sound bell when new data will add
- Can a scrollable date picker be done in WordPress for archives?
- No full page reload when navigating from page A to page B: is this possible with WordPress?