first your form that calls the ajax must have the an action filed with the value of the ajax hook
for example your ajax call is:
add_action('wp_ajax_show_all_tracks', 'show_all_tracks');
the your form action field must be:
<input type="hidden" name="action" value="show_all_tracks" />
thats for start’ so as for adding tracks you need to add a function to add javascript to the track edit form or add it to your code by changing
function add_post_enctype() {
echo '
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#post").attr("enctype", "multipart/form-data");
jQuery("#post").attr("encoding", "multipart/form-data");
});
</script>';
}
to
function add_post_enctype() {
echo '
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#post").attr("enctype", "multipart/form-data");
jQuery("#post").attr("encoding", "multipart/form-data");
jQuery("#Add Track").click(function() {
jQuery.ajax({
type: "post",url: "<?php echo admin_url('admin-ajax.php'); ?>",
data: {
action: 'add_track',
ad_type: jQuery( '#tr_name' ).val() ,
ad_type: jQuery( '#tr_time' ).val() ,
ad_type: jQuery( '#tr_lyrics' ).val() ,
_ajax_nonce: jQuery( '#nonce' ).val() ,
},
success: function(html){ //so, if data is retrieved, store it in html
if (html.indexOf('ok') > -1 || html.indexOf('true') > -1) {
alert('track added');
}
}
});
return false;
});
});
</script>';}
the create an ajax do action hook
add_action('wp_ajax_add_track', 'add_track');
then the function itself to add the tracks:
function add_track(){
check_ajax_referer( "add_track" );
/* save to the custom field array that holds the track data.
and return OK as string i know you can manage that*/
}
and last is change your form from:
<form id="add-track-form" name="add-track-form" action="" method="post">
<input type="hidden" name="mytheme_meta_box_nonce" value="'<?php wp_create_nonce(basename(__FILE__)) ?>'" />
<?php foreach($this->_meta_box['form'] as $el){
$this->display_field($el);
} ?>
<input type="submit" id="add-track" name="add-track" value="Add Track" />
to
<form id="add-track-form" name="add-track-form" action="" method="post">
<input type="hidden" name="nonce" id="nonce" value="<?php echo wp_create_nonce( 'add_track' ); ?>" />
<?php foreach($this->_meta_box['form'] as $el){
$this->display_field($el);
} ?>
<input type="submit" id="add-track" name="add-track" value="Add Track" />
</form>
hope this helps and its really more of a draft but it should get you in the right direction.
ohad.