Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author miunosoft

    (@miunosoft)

    Hi,

    To use data from a custom table is certainly possible. There is no tutorial for it at the moment as far as I know. However, it should not be hard to achieve once you understand how you use the framework.

    1. If you just need to list recipe items from your custom table, you just need to construct a label array and pass it to the label argument of the field definition array.

    2. If you need to synchronize the saved form data with your custom table instead of using the options table row created by the framework by default, you would need to use the options_{...} and the validation_{...} filter hooks.

    Which way are you looking for?

    Thread Starter Krollebolle

    (@krollebolle)

    I am not entirely sure what you mean in item 2, since I am not very into the framework at this point. Does it create some tables in the database for anything?

    What I do need, in more detail, is for example:

    1. Form for adding a new recipe:
    a) Create empty form.
    b) Fill empty form widgets with data: ingredient dropdowns/selects, difficulty dropdown/select, etc. Some widgets will remain empty for input.
    c) Verify input on form submission.
    d) Add new data in the database.
    e) Clear form on success, or similar.

    2. Form for editing an existing recipe:
    a) Create empty form.
    b) Fill a dropdown/select widget with existing recipe name. When a new recipe name is selected, fill the rest of the form with the existing data for that recipe.
    c) The user changes some of the data in the form.
    d) Verify input on form submission.
    e) Update data in the database.
    f) Clear form on success, or similar.

    Currently I am using something like this to get data for my test forms:

    function DB_get_recipes() {
        global $wpdb;
        return $wpdb->get_results(' SELECT name
                                    FROM recipes
                                    ORDER BY name', ARRAY_A);
    }

    Does this make sense for returning data to fill the form widgets?

    Plugin Author miunosoft

    (@miunosoft)

    Hi,

    In your case, it will be the second option I asked in the previous reply.

    Is there a reason that you don’t want to use a custom post type for it?

    Thread Starter Krollebolle

    (@krollebolle)

    Hi,

    I am not really sure what you mean. These forms are supposed to be available in the admin area of the site as a plugin, never anywhere else. Why would I need a custom post type for that? It might be that I am not too into the WordPress framework to understand what is going on.

    I will read up a bit more and see if I get more into it.

    Plugin Author miunosoft

    (@miunosoft)

    Hi,

    A custom post type can be used for a option container. You store form data into the meta fields of a post. The post type can be not public so you can disable unnecessary information to the public.

    Admin Page Framework supports meta boxes for custom post types and you can achieve what you described with a custom post type. However, some advanced developers still refuse to use it for efficiency and some other reasons.

    If you are okay with using a custom post type, there is a tutorial for it already. Do you have to use a custom database table or not mind using a custom post type?

    Plugin Author miunosoft

    (@miunosoft)

    Closing the topic due to inactivity.

    If I may answer the “Is there a reason that you don’t want to use a custom post type for it?” question:
    Sometimes, creating a new database table is a better option, than using custom post types(large set of data, lots of SQL queries, etc.).
    So, I understand that there is no tutorial for custom database tables, right?

    Plugin Author miunosoft

    (@miunosoft)

    Hello LeonidasMilossis,

    Check out the 2nd suggestion of the FAQ item, Is it possible to use a custom options data for the form instead of the ones used by the framework?.

    Hope it helps.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Populate admin page form with data from database’ is closed to new replies.