Saving repeating fileds
-
My plugins options page has repeating fields for one of the settings. I have the repeating part working but I cannot get the fields to save.
public function add_mimes_callback() { $option = $this->ordered_uploads_options; $mimes = $option[OU_PL_PREFIX . '_mimes']; $mime_folders = $this->mime_folders(); ?> <script type="text/javascript"> jQuery(document).ready(function($){ $('#add-row').on('click', function() { var row = $('.empty-row.screen-reader-text').clone(true); row.removeClass('empty-row screen-reader-text'); row.insertBefore('#repeatable-fieldset-one tbody>tr:last'); jQuery('input, select', row).val('').attr('name', function(index, name) { return name.replace(/(\d+)/, function(fullMatch, n) { return Number(n) + 1; }); }); return false; }); $('.remove-row').on('click', function() { $(this).parent().parent().remove(); return false; }); }); </script> <table id="repeatable-fieldset-one" width="100%"> <thead> <tr> <th>Extention</th> <th>Filetype</th> <th>Folder</th> <th></th> </tr> </thead> <tbody> <?php $counter = 1; if( $mimes ) { foreach( $mimes as $mime ) { $counter++; $extention = $option[$mimes]['ou_mime_extention_' . $counter]; $filetype = $option[$mimes]['ou_mime_filetype_' . $counter]; $folder = $option[$mimes]['ou_mime_folder_' . $counter]; ?> <tr> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_extention_<?php echo $counter; ?>']" value="<?php echo $extention; ?>" class="all-options"> </td> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_filetype_<?php echo $counter; ?>']" class="all-options"> </td> <td> <select name="ou_options_settings['ou_mimes']['ou_mime_folder_<?php echo $counter; ?>']"> <?php foreach ( $mime_folders as $label => $value ) : ?> <option value="<?php echo $value; ?>"<?php selected( $field['select'], $value ); ?>><?php echo $label; ?></option> <?php endforeach; ?> </select> </td> <td> <a class="button remove-row" href="#">Remove</a> </td> </tr> <?php } } else { ?> <tr> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_extention_1']" class="all-options"> </td> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_filetype_1']" class="all-options"> </td> <td> <select name="ou_options_settings['ou_mimes']['ou_mime_folder_1']"> <?php foreach ( $mime_folders as $label => $value ) : ?> <option value="<?php echo $value; ?>"><?php echo $label; ?></option> <?php endforeach; ?> </select> </td> <td> <a class="button remove-row" href="#">Remove</a> </td> </tr> <?php } ?> <tr class="empty-row screen-reader-text"> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_extention_1']" class="all-options"> </td> <td> <input type="text" name="ou_options_settings['ou_mimes']['ou_mime_filetype_1']" class="all-options"> </td> <td> <select name="ou_options_settings['ou_mimes']['ou_mime_folder_1']"> <?php foreach ( $mime_folders as $label => $value ) : ?> <option value="<?php echo $value; ?>"><?php echo $label; ?></option> <?php endforeach; ?> </select> </td> <td> <a class="button remove-row" href="#">Remove</a> </td> </tr> <?php ?> </tbody> </table> <p><a id="add-row" class="button" href="#">Add Mime</a></p> <?php } // end mime_repeater
Here’s a link to the full code Gist
I’ve been trying to get this to work for days. Unfortunately, I can’t find very much on repeatable fields, so If any one can help me out I’d really appreciate it.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Saving repeating fileds’ is closed to new replies.