Support » Plugins » Hacks » comment form adjustment

  • hello there,
    im making a plugin wich enables users to upload images to the server and use them in comments. the part where the plugin puts in the images in the comments i already done. but now i wanted to make the upload form and i want to put it in the comment form. so i googled for how to do that and i have come up with this so far:

    //hooks:
    add_action('comment_form_logged_in_after', 'imagements_additional_fields');
    add_action('comment_form_after_fields', 'imagements_additional_fields');
    
    //function:
    function imagements_additional_fields()
    {
        echo '<p>' . '<label for="checkbox">' . __('upload image') . '</label>' .
            '<input id="checkbox" name="checkbox" type="checkbox" value ="yes"/></p>';
        echo '<p>' . '<label for="naam">' . __('name image') . '</label>' .
            '<input id="naam" name="naam" type="text"/></p>';
    
        echo '<p>' . '<label for="image">' . __('file image') . '</label>' .
            '<input id="image" name="image" type="file"/></p>';
    }

    i can see these fields clear in the comment form so that works. however, when i trie to process the info given in the form with the preprocess_comment filter, i find that the $_FILES variable stays empty whatever i try. this is weird because i tried it in a non-wordpress site (aka just a script with no markup on localhost) and there the $_FILES variable worked. even weirder is that i found a link on google wich uses the same variable in the same filter and gets it to work! so my question is, what am i doing wrong? thx in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • well i found that i need to add enctype=”multipart/form-data” to the form tag. i also found the hook for it. however when i use the same example as in the codex it still doesnt work! i cant even see the enctype in the source of the page when i test it. this means that the whole function is not fired. anyone know why? i used:

    add_action('post_edit_form_tag' , 'imagements_add_form_tag' , 1);
    
    function imagements_add_form_tag(){
        echo ' enctype="multipart/form-data"';
    }
    Moderator bcworkz

    (@bcworkz)

    I don’t know if this will help, but I added a comment field and processed my part of POST input using ‘pre_comment_on_post’ action. Retrieved the field value via the global $_POST array. Works fine for me.

    Can’t comment on changing the form’s enctype.

    I know i use that too. The problem is i need to get files uploaded so i need the files variable. The post works for me too in that hook. But thx for the input

    So my problem now is that the hook to change the enctype doesnt work, altough i use the exxact same code as the codex example. Anyone know what i do wrong. I already changed the priority of the action so it cant be that

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘comment form adjustment’ is closed to new replies.