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.

Doing my first plugin with 3.1 Everything is great, but I need to store the data now. My data is sufficiently complex that it requires custom tables (as opposed to options). So now I am wondering how I save the data. Normally, I would just create a processing page to handle it, but that doesn't seem like the best way within the WP API. How do I go about saving my form data from my plugin settings page into my custom tables? Thanks!

EDIT: To clarify, I know how to code it, I am not sure architecturally the best way to do it.

share|improve this question
    
If you can explain your use-case you are likely to get a better answer. –  MikeSchinkel Apr 10 '11 at 16:39
    
Thanks. Hmm, ok. I've got an admin page for my plugin. In the admin page, you setup a simple survey. (survey and question tables) I've got my form setup properly, I want to know where to set my form action. Do I send it to another page and redirect back to the whichever other admin page? Do I send the form back to the same page? Do I use AJAX? Or maybe it doesn't matter how I do it? Just trying to see if there is a best practice, otherwise I'll just go with a separate page and redirect back to the admin page (just seems kinda hackish) –  Wil Apr 11 '11 at 8:02
1  
For future reference it's best to explain your use-case in the question, not in the comments. Many people don't go to the extra effort to also read the comments. It also helps to include source code in your question that shows what you are currently doing. It's easier for us to fix your source code than to write it from scratch. –  MikeSchinkel Apr 15 '11 at 11:29
add comment

1 Answer

Not that there is specialized API for something exactly like that.

  1. Create your table, see Creating Tables with Plugins in Codex.

  2. Process submitted form (since you are not using higher APIs, don't forget to check for capabilities, use nonces and such).

  3. Write data to your custom table, using $wpdb.

share|improve this answer
    
I know all this, and I undestand it, but I am asking architecturally what is best. A seperate page to take the request and redirect? AJAX? Use the same page? Trying to understand best practice. –  Wil Apr 10 '11 at 14:25
    
@Wil best practice is Settings API :) If you need something else - then it's up to you how to put it together. Personally I'd probably try to use Settings API anyway, just writing data to database in sanitizing function instead of saving it as option. –  Rarst Apr 10 '11 at 14:27
add comment

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.