WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have never used WordPress before, but have done a lot of programming. But what is the normal way of making customs forms?

I need to create a form where a user fill some input fields and on submit will the data be stored in the database. No need for any email.

I also need to query the data and get the output in a HTML table.


share|improve this question
Here is an example for user data. – toscho Dec 25 '12 at 23:49

My suggestion:

Use Contact Form 7 plus Contact Form DB. You can "design" your form in the backend and putting in the frontend via a simple shortcode.

The Contact Form DB extension let you put your data in the database and offers to you shortcodes to display it (or you can query the data directly from the database if you prefer)

share|improve this answer
I have tried Contact Form 7 and it look great but I do have some question. Is it possible to add a incremental/identifier as column to the table. I also need to set the dropdown values based on a tables values. I have never works with a CMS before and don't know how much you should and need to customize your self. – boje Dec 26 '12 at 20:48

I got the problem solution myself. See the code below this will do that.

Put the code inside your newly created custom template.

        if (!empty($_POST)) {
        global $wpdb;
            $table = wp_achord;
            $data = array(
                'name' => $_POST['yourname'],
                'chord'    => $_POST['chord']
            $format = array(
            $success=$wpdb->insert( $table, $data, $format );
            echo 'data has been save' ; 
else   {
        <form method="post">
        <input type="text" name="yourname">
        <textarea name="chord"></textarea>
        <input type="submit">

       <?php }  ?>
share|improve this answer
Oh my god. not even a single form of validation. – Michelle May 10 '15 at 10:53

It give different ways. For store data, like options is the options table, the options API, the right place with a entry and a array as store element. But for store data to use it like posts and each request from the form is it better to save also like post. But also here different possibilities. You can save for different post types. The default is 'post' and also you can save in a custom post type. Use the function wp_insert_post() to save for all post type after send Form from users. You find very fine answers here to this function, this topic ans also in the wild of www. You can also see a small example in this answer 73653, inlcude attachments in the form.

share|improve this answer
by using the 'wp_insert_post()' is that not only for comment. And if not why do is it good to use that one? I don't get the options table idea. A quick search on Google don't help me :( – boje Dec 26 '12 at 20:59
The wp_insert_post() is not for comments, is for post content, create an new post. I update my answer now, was from mobile; not realy easy on WPSE. The other answer with the hint to plugins is the same, Contact Form 7 or other create new posts, but you have the requirements of a plugin. If you will control this, also the source and have enough knowhow about coding, then is a custom plugin to create posts the best way. – bueltge Dec 27 '12 at 12:29
Thanks for your help so far Bueltge. My understanding of wp_insertpost is that it is a help-function for quick and save insert something into a database-table. If i have a table(name=Course) with these column(id, coursename, paricipant, startdate, enddate). Where do i define the tablename? Maybe I understood it comeplety wrong. Code example link – boje Dec 28 '12 at 9:50
No, the function create data in the default wordpress tables; minimum in _posts and if you have attachments or post meta data also in the other tables, there are in nabership with post. But you ask for save data from form in wordpress and I think, this is the best way. You have without work a UI with many solutions for edit and maintenance the items from form. If you see the code from my behaviour link, then you see the solution. – bueltge Dec 28 '12 at 11:41
Thanks, think i need to read some more or find some tutorials to understand the setup better – boje Dec 28 '12 at 12:02
up vote 0 down vote accepted

I am going to use this solution, but it seams to be very customize and can that be a problem with themes and upgrades?

share|improve this answer
The way I see it, you should separate the logic from the template file. Your method that handles the POST data should be located in functions.php and initialized by a initialization hook. To only handle the submitted data for a specific page template, you could check for a named (optionally hidden) input field that's unique for that template. You could also benefit of using is_page_template() – estrar Jul 11 '14 at 6:50

Your solution is good and may work very well. But, there are few limitations. eg:

1) What about searching and sorting entries which are posted through your form? 2) What about exporting the data filled into your form to Excel or CSV or PDF? 3) What if you want to print the inserted data.

All that can be achieved with Contact Form 7 + Save Contact Form 7 plugins.

both are free widely used plugins: http://savecontactform7.com/ http://contactform7.com/

share|improve this answer
Please disclose your affiliation and make answer specific to the requirements of the question. This reads more like advertisement than genuine solution. – Rarst May 20 at 14:55
I agree, this looks like an advertisement, and I am an owner of the Save Contact Form 7. But, the solution and answer perfectly aligns with the requirement of the question. So, this is definitely going to help the person who asked the question. – Nimblechapps May 22 at 7:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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