[wp-hackers] Form in metabox, like Custom Fields

Viper007Bond viper at viper007bond.com
Thu Sep 4 13:40:26 GMT 2008


Are you trying to create a meta box in general?
http://codex.wordpress.org/Function_Reference/add_meta_box

Or specifically an AJAX-powered one like the Custom Fields one?

On Thu, Sep 4, 2008 at 6:32 AM, Peter <peter at avirtualhome.com> wrote:

> I would like to create a metabox in the admin post and page section
> with a "form" inside.
>
> What I have right now is the following javascript:
> jQuery(document).ready(function() {
>                jQuery('#mysubmitbutton').click( metabox_mysubmit );
>                }
>        );
>
> function metabox_mysubmit() {
>        var values= new Array;
>        values[0] = jQuery('tab-id').attr('value');
>        if (values[0]) {
>                metabox_submit('find','#mymetabox-output',values);
>        }
>        return false;
> }
> function metabox_submit(this_action, this_output, this_values){
>        jQuery.post(
>                jQuery('#mb-url').attr("value")+"/wp-admin/admin-ajax.php",
>                {
>                 action: 'my_metabox',
>                'cookie': encodeURIComponent(document.cookie),
>                'mb_action': this_action,
>                'mb_values[]':this_values
>                },
>                function(data, textStatus) {
>                         jQuery(this_output).html(data);
>                }
>        );
> }
>
> Together with the PHP and HTML code this works, except for when you
> press enter, I need to add jQuery('#myinput').keydown(metabox_myinput);
> and check for key 13 in the metabox_myinput function. I know how to do
> this, just haven't got to it.
>
> In the end this solution will work, but I have been looking at the
> Custom Fields metabox and have been wondering how that one works. I
> would love to write my piece of code the same way this one is written
> but I can't seem to figure it out.
> Is there documentation on how this is done? Could somebody direct me
> how to do this or maybe it's not possible at all.
> I think it has to do with the class assigned to the submit button, but
> my javascript knowledge isn't completely up to par to figure it out
> myself without some direction.
>
> Thanks in advance.
>
> --
> Peter van der Does
>
> GPG key: E77E8E98
> Blog: http://blog.avirtualhome.com
> Forums: http://forums.avirtualhome.com
> Jabber ID: pvanderdoes at gmail.com
>
> GetDeb Package Builder
> http://www.getdeb.net - Software you want for Ubuntu
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Viper007Bond | http://www.viper007bond.com/ | http://www.finalgear.com/


More information about the wp-hackers mailing list