I created simple contact me form and want to post form data to PHP page where data will be stored.

I am unable to figure out where to upload create_form.php file. Blow is my code.

<form name="customer-details" method="POST" onsubmit="return  formValidation() action="contact_form.php">
<legend>Personal information:</legend>
<input type="text" id="name" name="name" placeholder="Your Name"><br>
Company Name:<br>
<input type="text" id="company" name="company" placeholder="Your company Name"><br>
Email Address*:<br>
<input type="email" id="email" name="email" placeholder="Your Email Address"><br>
Interested in:<br>
<input type="text" id="interest" name="interest" placeholder="Interested in"><br>
Your query*:<br>
<textarea id="query" name="query" placeholder="Your query here(more then 10 words)..."></textarea><br>
<button id="submitBtn" name="submitBtn" type="submit">Submit Form</button>

I saved contact_form.php file inside my themes folder. When I click on submit button, page is not found. Which is correct path to put contact_form.php file.

1 Answer 1


You would never create a create-form.php, doing so would introduce a security problem.

For example, lets say your client changed themes, this contact form would still work. Even with the theme deactivated. The same is true of any form handler, AJAX handler, or endpoint for a remote service that directly accesses a PHP file inside a theme or plugin.

WordPress is a CMS, it's supposed to handle all the requests made to it, not individual files in a plugin or theme

Instead, don't specify an action on your form, include a hidden input to check against, and then look for that input to handle your form input, e.g.:

// Template
<form method="POST">
    <input type="hidden" name="aviras_contact_form" value="contact_form">

// functions.php
add_action( 'init', function() {
    if ( empty( $_POST['aviras_contact_form'] ) ) {
    // handle form submission

For AJAX, use register_rest_route ( consider asking a new question on how to do that ). For 3rd party call ins or handlers, use rewrite rules or check for parameters

Also, indent your code, all the major popular editors today all auto-indent for you and have packages to reindent and beautify automatically ( PHPStorm, Netbeans, Sublime Text, Coda, etc etc )

  • I followed this guide - inkthemes.com/… Blogger did the same, uploaded the php file inside themes folder. Have a look. Oct 1, 2016 at 17:41
  • 1
    That blogger is wrong, not everything you read online is the best way. Keep in mind that if you create your own file, you'll have to bootstrap WP which means reaching up several folders to include a file, and you still have the problem that the contact form handler will run even when the theme is deactivated
    – Tom J Nowell
    Oct 1, 2016 at 17:42
  • 1
    I've commented on said blog, pending approval. To be honest, from what I read, it wouldn't work anyway. The guy never tells you to create the database table, makes assumptions about where the create_form.php is located and includes no server side sanitisation. You'd be much better off ignoring it or using a plugin such as Ninja Forms ( free ) or Jetpack
    – Tom J Nowell
    Oct 1, 2016 at 17:52
  • exactly even including JavaScript does not work that way. I had hard time figuring out that and then added js code inside header template Oct 1, 2016 at 17:55
  • the wp_enqueue_script function and hooks is what you want there :) best to ask a new question for that though
    – Tom J Nowell
    Oct 1, 2016 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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