Support » Plugins » Changing the form enctype dynamicly

  • Is there a way (by a plugin function) to change the form enctype (in new post form) to multipart/form-data

    The problem is that I don’t want to edit the file always after upgrading the WP source.

Viewing 1 replies (of 1 total)
  • Hello Kurak,

    Here is a simple solution to your problem using jQuery:

    if ( is_admin() ) {
        function add_post_enctype() {
            echo "<script type='text/javascript'>
                      jQuery(document).ready(function(){
                          jQuery('#post').attr('enctype','multipart/form-data');
                      });
                  </script>";
        }
        add_action('admin_head', 'add_post_enctype');
    }

    If you want to test for a particular admin page for example “add page” or “edit-page” here is a slightly improved version of the same script:

    if ( is_admin() ) {
        $current_admin_page = substr( strrchr( $_SERVER['PHP_SELF'], '/' ),1, -4 );
        if ( $current_admin_page == 'page' || $current_admin_page == 'page-new' ) {
            function add_post_enctype() {
                echo "<script type='text/javascript'>
                          jQuery(document).ready(function(){
                              jQuery('#post').attr('enctype','multipart/form-data');
                      });
                      </script>";
            }
            add_action( 'admin_head', 'add_post_enctype' );
        }
    }

    Using this method you can add all sorts of attributes or html to the admin pages when and where needed.

Viewing 1 replies (of 1 total)
  • The topic ‘Changing the form enctype dynamicly’ is closed to new replies.