I have a form:
<form name="customer_details" method="POST" onsubmit="return form_validation()"
action="../customer-details.php">
I placed the PHP file in my theme folder, but WordPress gives me an error:
404 — Fancy meeting you here!
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI have a form:
<form name="customer_details" method="POST" onsubmit="return form_validation()"
action="../customer-details.php">
I placed the PHP file in my theme folder, but WordPress gives me an error:
404 — Fancy meeting you here!
Add unique field in your form.
Eg: <input type="hidden" name="wdm_action" value="1">
Put your 'customer-details.php'
file code in below function:-
add_action('template_redirect','wdm_customer_details'){
//check if that field present in the form, if yes then perform the action
if(isset($_POST['wdm_action'] && $_POST['wdm_action'] != ''){
//customer-details.php file code
}
}
You can just define an action method in function file and leave form action blank.
Use hook init by
add_action('init',formaction);
function formaction() {
if($_post['submit']=='1') {
//form submit code here
}
}
For know more about creating page template read this.
<?php
echo esc_url(get_permalink(100));
?>
Please note 100 is the ID of the page you have created "x form action".
Now you are good to write your form action code in the file page-xaction.php
Also read about wp_nonce here
You should change this (if you dont use that php
file directly, like example.com/customer-details.php`):
action="../customer-details.php"
to
action=""
instead, you should use that as page template
, then change to:
action="example.com/pagename"