-1

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!

2
0

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

}
    }
0

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 
    }
}
0

1 You need to change the form action and easiest way to do is creat a page with name like "x form action" (slug xaction). Now publish it and create a page template for this page like "page-xaction.php".

For know more about creating page template read this.

2 Now change the form action like 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

0

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.