I have creating a template page in which i have a form, upon testing it gave a 404 error. should i putting something else in action?
`<form action="results.php" method="post"> <!--my code--> </form>`
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 community
i putting something else in action?
Yes. The complete path to the file. If your site is
http://mysite.com and you are on the home page then you are requesting a file at
http://mysite.com/result.php. If you are on a date archive you'd be requesting a file at
http://mysite.com/2013/03/03/result.php. The file you want is actually at
http://mysite.com/wp-content/themes/theme-name/result.php. See the problem?
But I would say that even if you were to construct a complete URL to the template file that you are still doing it wrong. If you load a file like that then none of the WordPress core loads and you tend to get undefined function errors.
The right way to do this, in my opinion, is ...
to send the request to the same template file as contains the form.
<form action="<?php the_permalink(); ?>" method="post">
That particular code only works in some circumstances so you may
need to construct the URL differently, using
site_url(), for example. You can usually just omit the action attribute (as prompted by Milo).
wp_headand process the form on that hook.
If you form appears on more than one page you will need one of option 2 or 3. Otherwise, use the first option.
If you need the form to appear on one page and the results on another, then you will need a custom page template for each component, and you will need to create a page for the form and another for the results via the "Pages" section of the WordPress backend.