[wp-hackers] meta box and input field seem not to work on writing post/page

scribu scribu at gmail.com
Wed Sep 16 18:15:25 UTC 2009


The thing is that the request is sent to post.php and then redirected
to edit.php.

So you have to hook into 'save_post' and store the POST data in the
database to be able to retrieve it later.

On 9/16/09, Pasi Koponen <pasi.koponen at eetanet.fi> wrote:
> This is my first message in here so sorry if you have allready covered
> add_meta_box() (
> http://codex.wordpress.org/Function_Reference/add_meta_box ) function
> and usage in here and picking up PUT/GET http commands on post/page
> writing page.
>
> I am fidling around with posts and pages meta box. It seems that I
> cannot get <input type="hidden" ....> to work right. I have googled and
> searched around and it seems that I am doing something totally wrong.
> Does anybody have an idea where I am doing stuff wrong. Here is a simple
> "Hello World" plugin to illustrate the problem. It seems that wordpress
> is messing around in writing post/page the $_REQUEST['hellomessage'] and
> $_POST['hellomessage'] variables(this might not be the correct term).
>
> How the sample plugin works:
> It first creates the meta box by adding metboxHook to wordpress
> 'admin_menu' hook and creates meta_box to posts side panel. The sample
> plugin should send (pushing the update post button) to server(http POST)
> hellomessage which is first echo:ed out by $_POST and after that with
> $_REQUEST (just for testing). So basicly in the metabox there should
> became text "Hello World" after submitting editing post. It seems not to
> work and I am totally clueless what I am doing wrong.
>
>
> Here is the sample plugin to illustrate the problem:
> --X<---X<---X<---X<---X<---X<---X<---X<---X<---X<---X<--
> <?php
> /*
> Plugin Name: metaboxtest
> Plugin URI:
> Description: testing metabox
> Version: 1.0
> Author: basix
> Author URI:
> */
> ?>
> <?php
> /*
>    This program is free software; you can redistribute it and/or modify
>     it under the terms of the GNU General Public License as published by
>     the Free Software Foundation; either version 2 of the License, or
>     (at your option) any later version.
>
>     This program is distributed in the hope that it will be useful,
>     but WITHOUT ANY WARRANTY; without even the implied warranty of
>     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>     GNU General Public License for more details.
>
>     You should have received a copy of the GNU General Public License
>     along with this program; if not, write to the Free Software
>     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> 02110-1301  USA
> */
> ?>
> <?php
> if(!class_exists(metaboxTest)){
>     class metaboxTest{
>         function metaboxHook(){
>                 add_meta_box('hellomessage', 'hellomessage', array(&
> $this,'metabox'), 'post', 'side', 'high');
>         }
>         function metabox(){
>             printf('<label for="hellomessage">Hi</label><input
> type="hidden" id="hellomessage" name="hellomessage" value="Hello World"
> />');
>
>             echo $_POST['hellomessage'];
>             echo $_REQUEST['hellomessage'];
>         }
>     }
> }
>
> if(class_exists(metaboxTest)) {
>     if(!isset($mBox)) {
>         $mBox= new metaboxTest;
>         add_action('admin_menu', array(& $mBox, 'metaboxHook'));
>     }
> }
> ?>
>
> -X<---X<---X<---X<---X<---X<---X<---X<---X<---X<---X<--
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


-- 
http://scribu.net


More information about the wp-hackers mailing list