Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks

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

4 Answers 4

up vote 0 down vote accepted

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

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

Put the code inside your newly created custom template.

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

       <?php }  ?>
share|improve this answer

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

Link to solution: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme

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 at 6:50

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

Your Answer

 
discard

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.