$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - $_POST from a Meta Box|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - $_POST from a Meta Box

matteradmin9PV0评论

From my reading, the editor page of a post is wrapped in a form tag meaning a standard HTML form won't work within a Meta Box.

What I'm trying to achieve is a meta box with two fields e.g. Name & Email and a button. When the button is pressed, a POST request will be sent. I can't use AJAX in this instance.

I can render the meta box and a button, along with a simple href link, but is there a way to generate an HTML form, or an alternative method, to replicate POST functionality?

Example Code, I've removed some of the hooks for brevity.

function lx_add_paperwork_meta_box() {
            add_meta_box(
                'my_meta_location',
                'Generate Paperwork',
                'display_generate_button',
                'document',
                'side',
                'default'
            );
}

function display_generate_button() {

    output_generate_button( __( 'Create Paperwork', 'my-invoices' ), 0, 'paperwork-generate', array( 'class="button"' ) );

}


function output_generate_button( $title = 'Create', $order_id = 0, $action = 'none', 
    $attributes = array() ) {

            $url = wp_nonce_url( add_query_arg( array(
                'post'         => $order_id,
                'action'       => 'edit',
                'paperwork_action' => $action,
            ), admin_url( 'post.php' ) ), $action, 'nonce' );

            $attr_title = $title;

            printf( '<a href="%1$s" title="%2$s" %3$s>%4$s</a>', $url, $attr_title, join( ' ', $attributes ), $title );

}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far