settings api store multiple array

I put this in the form so it knows its editting:

<form method="post" action="options.php">

     <?php settings_fields('venues_section'); ?>
     <input type="hidden" name="editmode" value="<?php echo $editmode; ?>" />
     <input type="hidden" name="venue_id" value="<?php echo $venue_id; ?>" />
     <?php submit_button(); ?>

</form>

The receiving validation function can then handle that by doing something like this:

function venues_validation_callback($input){

    $venues = get_option('venues'); // Get the current options from the db (Edit 
                                    // this and return the full modified version)
    $editmode = $_POST['editmode'];  // add, edit or delete     
    $venue_id = $_POST['venue_id'];             

    if($editmode == 'add'){

        // Do Add Logic

        return $venues;

    elseif($editmode == 'edit') {

        // Do Edit Logic

        return $venues;

    }
    elseif($editmode == 'delete'){

        // Do Delete Logic

        return $venues;

    }

    return $input; // only triggered if none of the above are called
}

That’s just to show its possible. There’s quite a lot of other ins and outs to it as well its a pretty custom solution. I’ve got it working but its taken a week and given me a few headaches doing it I’ll be honest. But there you go that’s about as much as I can do. Hopefully there’s a plugin that could do it I hadn’t found. It’d be nice to make it if it hasn’t already if i had time.

Leave a Comment