I have a custom plugin, using a custom post type for data entry capabilities in the admin section. I would like to use a textarea form, along with the checkboxes, select and text input fields I am presently using. However when I update the bost, my call back receives all the other input fields, not not the textarea field.

The code is rather large, covering lots of different input types, this is a refinement of that draw and save call:

function  CustomInput()
{
add_meta_box( 'List_Group1',
           __( 'Lists - Card Records : Manual Input', 'myplugin_textdomain'  ),
              'DrawCallBack',
              'customlist',
               'normal',
               'high',
               $args
               );           
 }
 add_action( 'add_meta_boxes', 'CustomInput' );
 add_action( 'save_post', 'SaveFields');


function DrawCallBack($post)
{
$Record = GetDBRecord();
echo '<textarea id="bizdesc" rows="2" cols="50">';
echo $Record['BizDescp'];
echo  '</textarea>';

echo '<input type=text id="YourName" name="YourName"  value="' .$Record['Name'] .'"/>'
}


function SaveFields($post_id)
{
$screen = get_current_screen();
if(strcmp($screen->post_type, 'customlist') !=0)
   return;

$Desc = sanitize_text_field( $_POST[ 'bizdesc ' ] ); 
$Name = sanitize_text_field( $_POST[ 'YourName' ] ); 
}

The standard input field comes in nicely and correctly. The textarea field does not. Not sure why?

Any ideas?

2 Answers
2

You forgot to add name ="bizdesc" to your textarea, so this

function DrawCallBack($post)
{
  $Record = GetDBRecord();
  echo '<textarea id="bizdesc" rows="2" cols="50">';
  echo $Record['BizDescp'];
  echo  '</textarea>';

  echo '<input type=text id="YourName" name="YourName"  value="' .$Record['Name'] .'"/>'
}

should be

 function DrawCallBack( $post )
 {
  $Record = GetDBRecord();
  echo '<textarea name="bizdesc" id="bizdesc" rows="2" cols="50">';
  echo esc_textarea( $Record['BizDescp'] );
  echo  '</textarea>';

  echo '<input type="text" id="YourName" name="YourName"  value="' .esc_attr( $Record['Name'] ) .'"/>';
}

I hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *