• gplaurin

    (@gplaurin)


    Hi,
    This is my first post, hurray !

    I’ve created a plugin that is displayed when you create or edit a page.
    It let the user select from a multiple select the packages he want to be displayed in is new page.

    But when I tried to save these infos, I can’t retrieve the data from the select. I’ve got some other textbox and I can save them but nothing comes form my multiple select.

    Here is my select:
    <select name="includedpackage[]" id="includedpackage" style="width:80%;height:100px; float:left;" multiple="multiple"></select>

    And retrieve it with:
    $packages = $_POST['includedpackage'];

    Thanks a lot !
    GP

Viewing 3 replies - 1 through 3 (of 3 total)
  • mores

    (@mores)

    I’m not sure I understand.
    Your plugin gives the user some options, right?
    Where are they displayed? Like in a box on the side?

    Normally you then save these as post options, like
    update_option('packages',$packages);
    To set an initial set of options, you do this
    add_option('packages','value_of_packages','available options','yes');

    To retrieve use
    $packages = get_option('packages')

    I suggest you check out simple plugins to see how they work.

    Thread Starter gplaurin

    (@gplaurin)

    Hi !
    Using the add_meta_box('forfait','Forfaits','forfaits_meta','page'); I have put a box under the editor, in this box i have a multiple select. The user can add some package into the multiple select by entering the package name into a textbox and clicking add, then the text is add to the multiple select.

    But when I save my page using add_action('wp_insert_post', 'my_function'); and then in the function my_function I tried to retrieve my multiple select (includedpackage) with:
    $packages = $_POST['includedpackage'];
    $packages is empty

    BUT I FIND THE SOLUTION !
    It was easy, when I was saving my page, there was none item selected in my multiple select so nothing was post !

    Thanks
    GP

    mores

    (@mores)

    In that case you should first check if there is anything selected:

    if (isset($_POST['includedpackage'])) {
     ...
    }

    … No wait, that’s how I check if a button was pressed ??
    Uhm, then use this:

    if ($includedpackage) {
    ...
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple select when creating new page’ is closed to new replies.