0

My question is very simple but the answer I'm not sure if will be that simple. I'm developing a website for a non-profit organization where people can fill out a form containing questions usually asked by a doctor. Once a user submits the form I would like to grab the answers and display them in the backend so that Doctors(with Editor role) can see them and if approved can send an email with a solution.

To be more specific, there can be more than 1 users submitting the form and I want all of the users form entries displayed in a new section in the admin panel as posts or something. So, if 10 people seeks help by submitting the form will have 10 form entries available in the admin section for Doctors to view.

Do I need a custom DB table to store the form data? If so, how may I go about grabbing and storing them in the database?

How can I add a new section in the admin panel something like Patients where all the form entries by users will be displayed for the Doctors to view? I know how develop custom_post_type, custom_taxonomy and custom_meta_boxes but I don't think they are appropriate in this case.

I hope I was able to explain the scenario clearly. I hope someone can come up with a solution and this might help other people as well.

2
  • Sounds like an awesome project. Trouble is, this question is extremely broad and covers a multitude of requirements (front-end forms, backend pages, user permissions, opinion-based techniques) and really isn't suited for WPSE. If, when you get started, you hit a specific problem/need to know how to do something specific, feel free to ask away. FWIW, I would suggest using custom post types to store your data, and leveraging capabilities for who can read/edit/delete them. Or do a complete 180 and use Gravity Forms ;) Mar 7, 2015 at 16:13
  • 1
    Ok I'm going to be more specific here. Can you just tell me how I can grab the input value for "name" and add the entry to custom_post_type? I can figure out the rest Mar 7, 2015 at 16:15

1 Answer 1

2

Can you just tell me how I can grab the input value for "name" and add the entry to custom_post_type?

Sure thing:

if ( isset( $_POST['name'] ) ) {
    $name = sanitize_text_field( wp_unslash( $_POST['name'] ) );
    if ( $name ) {
        wp_insert_post(
            array(
                'post_title'  => $name,
                'post_type'   => 'my_post_type',
                'post_status' => 'publish', /* Or "draft", if required */
            )       
        );
    }
} 
3
  • 1
    awesome thanks. One more thing please. Assuming the post title is the "name", what will I use for the input "age"? Or "height"? Since I would like to display them in the my_post_type section in the backend how do I display the entries posted by a user? like I said, 10 users submit the form, will have 10 custom post containing their form data. Mar 7, 2015 at 16:23
  • Use post meta to store arbitrary data for each post. Read up on customising the backend table to show the data. Mar 7, 2015 at 16:36
  • thanks I'm giving it a try. The link you mentioned will help too :) Mar 7, 2015 at 16:44

Your Answer

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

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