0

I have the following form in a Wordpress page :

<form action="dbsearch.php" method="POST">
 <input name="input" type="text"> <select name="search4" size="1">
 <option selected="">option1
 </option><option>option2
 </option><option>option3
 </option><option>option5
 </option></select>
 <input value="Go!" type="submit">
</form>

The form provides the user an interface to search for data stored in a database. I have created a custom page, page_dbsearch.php, by coping page.php and renaming it. There I want to put the php code to query the database and show the results. It is placed in the theme directory. In fact in the child theme directory. I have use the information from https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#creating-a-custom-page-template-for-one-specific-page

The problem is when I use the form it shows the 404 not found page and not page_dbsearch.php. I have tried changing several things but it did not work.

I am new to Wordpress and I would appreciate it if someone can help me with this.

Thank you.

1 Answer 1

1

A helpful clue would be to look at the URL in the address bar of your 404 page. A reliable approach for form action in WP looks like the snippet below.

<form method="post" id="thisform" action="<?php bloginfo('url'); >/dbsearch/">

I would create your page in WP, ensure the page slug is 'dbsearch' as this determines your permalink (http://domain/dbsearch) and the template used. You can of course use any slug you like but match this to your form action. Rename your script 'page_dbsearch.php' to 'page-dbsearch.php'. WP will pick this up as the page template for your results page.

All of your form data will be available in the $_POST array to write your DB query with.

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.