230 thoughts on “Review of Posting From Front End Form”

  1. Hello and thanks for this great tutoring.
    I am looking to implement this in a user generated content project, but I would like to let user upload their pictures any idea on how I could truly implement this codes with it?

      1. What I am trying to say is using your idea to let a user upload picture and display that picture in different size based on wordpress 3 thumbnail capability. a small picture size for the archive and a bigger size for the single post view.

        1. OK, that’s really simple. I’ll make a quick post to help with that. If you have the above code working, that’s the hard part. Adding image sizes is really simple. It’s only an extra line of code per image size in functions.php, and another line of code where you want the image displayed.

          1. Did you ever post the line to change the imager size to medium and large?
            I’d like to know that as well!

          2. Well if you look here: http://vudu.me/5f It’s my discussion on featured images. All you have to do is register the various sizes you need to work with in functions.php, and then call each appropriate image size in the proper template where you want it displayed. As for calling specific image sizes for attached images, let me take a look at my code above real quick and see what I can figure out.

          1. Cool, thanks for the link! I’ve never messed around with timthumb, though I see it used a fair bit. I like to stick with what WP has built in. But one of these days I’m going to have to check that out.

  2. Thanks for the awesome tutorial. It has really helped me out a lot.

    I’m using it to build an online application. How can I disable the title and description checks? Simply commenting them out doesn’t work.

    Thanks Rev. Voodoo!

  3. Hello to all
    One question. When you let them upload picture what they see, the wordpress upload picture pop up with all the gallery, library tabs, where they can see and delete what ever they want?

    I haven’t tried the code, just asking before I’ll go in to it.

    thanks a lot 2046

    1. No, not at all. There is no back end integration like that. Basically your user would fill out the form and select their picture. When they hit submit, the post is made with their picture. IT either posts, becomes a draft, etc, depending on what you set in the code. But there is no opportunity to edit, or work with the media gallery, etc.

  4. .. which is grate :)

    one more thing.
    How to determine the user. The post is posted without user which is non-standard solution.

    thx 2046

    1. That’s a good question! I hadn’t actually worried about it since I only allow logged in users to post. I guess if you allow guests, it has no author. I’m sure you could work around that with some creative conditionals.

      Like in the form use a conditional to check if logged in, if so do nothing. If not ask for a name with a meta box.

      And then when displaying the post, check for the name meta value. If there is one, display it, otherwise use the normal author.

      I did just test, and the post works fine with no author, so the above concept should work for getting a name displayed

  5. thanks for the quick reply.
    ..but don’t you know the function I have to use that let me save the “user name” along the data?

    I know I have never enough…is there any chance make some “custom field” required?

    thx 2046

  6. OKi that was easy one
    ‘§post_author’ => ‘subscriber’,

    and what about the required filed. Do you think I should check the fileds by Jquery or something?
    Or do you have something more funcy?

    thanks again 2046

    1. Jquery is probably the best way. I was asking the same question on stackexchange’s wordpress area. I was hoping for some simple WordPress built in functionality, but I didn’t get an answer about that. If I find something better, I will definitely make a post about it.

    1. I’m confused what you are doing? post_author=>1 will assign all posts from the form to the main admin…..is that what you want? I don’t use post_author in my form, because post author automatically gets set to the logged in user making the post…..so in that case, no reason to assign a post_author. What you are doing above will assign all posts to the main admin, is that what you are wanting?

      1. Well, How could I make sure the post is actually uploaded by a login user and the post is assigned to his account if I have a taxonomy called Dealers(Users) so I could later on retrieve posts per users?
        I am trying to build a free car sale site where people can register and upload their car info for sale. and also a job posting board.
        Thanks for your great tutorials, thank to you I am addicted to wordpress.

        1. I have been working to making sure only a register user can use the form, or visitor need to register first, but I can’t figure out where to place the code [ if login user (post) else (register) or login]

          1. Hello you can add the code
            above the tag

            and after the tag add:

            <?php else : // if not logged in go to login page

            echo ('Onlky register user can see the form‘);

            endif; ?>

            Bye

          2. @Stew has some good advice, but it seems they code is being eaten up and not displayed. But yes, you can simply wrap up the form in a conditional checking if the user is logged in.
            http://codex.wordpress.org/Function_Reference/is_user_logged_in
            Is the codex page with a simple example. You should be able to work with that. Wrapping your form inside that to only show to logged in users, and displaying some sort of message to non-logged in users asking them to login or register.

  7. that’s just an example.
    In real life it’ll be good to create a say anonymous user and then put there his number indeed (..even better check who is logged in then use his number, if nobody then use the anonymous one) .
    The reason why it is worthy is that you can then filter out all his (anonymous) posts and check them for spam, unlike when there is no user and so it’s not easy filterable (in backend) and you cannot process them further based on this anonymous issue…or you can associate those posts to some user who’ll be in charge ;)
    This is all applicable in the case you let them post anonymously.

    btw then it’s good to use some sort of captcha like quaptcha in my case :)
    http://www.myjqueryplugins.com/QapTcha/demo

    1. Ah, I’m following you now. If that works for you, awesome! Just a word of caution on a captcha. A lot of people like them, but they really don’t work well. There’s a lot of stuff on google about how easy they are to bypass. Also (and this may not be a concern on a smaller personal site) I use my post form on a business. Captchas are not accessible, which is bad form for a business, and could present legal issues.

  8. I do not like captchas as well, but this one seams pretty easy for users plus they won’t publish their credentials, nothing like that.
    Spam is natural thing, I’m used to it.

    thanks a lot for your work, it helps me immensely . 2046

  9. yup, that line would work great under the wp_se_post_tags that we have in the example. It works similar, but for taxs. Thanks for reporting back with your suggestions, much appreciated!!

  10. Love that! But Theres no way to add some more dropdowns with taxonomies for post types?! I had tried everything! When using post types, theres only taxonomies isn’t?

    1. I don’t fully understand your question. You have some taxonomies registered for custom post types? And you would like to add those instead of cats and tags? I’d love to help if you could perhaps clarify just a bit for me.

      1. Thanks for quick reply. I solved this! Not sure if right way, but it works: Just added another i.e.
        wp_set_post_terms($pid,array($_POST['job_states']),’jobplace’,true);

        And then, added a dropdown, but you must write up a code for get terms and echo every item (can't remember the code right now, I will post here later ok.) The select field id must be then 'job_states'.

        Now I have another issue :( :

        I have another taxonomy, but this one should use checkboxes, I know how to get the metadatas in checkboxes, everything looks right in the rendered code, but it doesn't saves. How to do that?

        Also, I need radios for 3 metadatas, don't know how to do either :( This one is easier since the itens should be passed directly.

        1. I’ll try to take a look at the radios and checkboxes, to ensure everything saves. I’m currently really tied up with work and school…. but hopefully I’ll get a chance to play with it soon

          1. Oh I see. I just read your post about checkboxes and radios for metadata and that worked, thanks a lot. Now I need to discover how to save another taxonomy using checkboxes.

          2. @Diana, you are looking to feed the taxonomies into checkboxes? That should work with a simple foreach loop. That way you can grab you taxonomy and loop through the terms, assigning each a checkbox. Are you familiar with foreach loops? I have used them a bit around the site here, but haven’t explained them in detail too much

  11. Thanks for your help Rev. Voodoo
    This is site is my Alibaba Cave, I am always here to find great resources. I have implemented the form in many site, but now I need to upload multiple files (photos). I was wondering how can I use one input type=file to get certain number of photos (10) and have them listed under and be able to delete any chosen file (photo) before submitting it. I found out this resource at [http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/], but I have no idea how to implement the same thing using your code.
    I will appreciate any help from anyone. thanks

    1. I’ll take a look at that code as soon as I get a chance. I have found some really good form examples, so as soon as I get a break from school, I am going to revise my front end posting form to get better validation in place. And to clean up the code, etc. That would be a good time to get some new features in place. I don’t currently know how to do what you are asking, but I am a big fan of looking into new things to figure it out, and I like the idea of what you are asking…. I would find that a useful feature.

  12. Hi Voodoo
    I need help about redirect page after form submit.
    I’ll like after input send, display “thanks you page”, how i can do it it?
    Bye
    Stew

    1. Well, what kind of a thank you message? Like a different page, or just a box that says thank you? Line 42 and 43 in the above code are the redirect. Line 42 currently defines $link as the permalink of the new post. You could make a new thank you page and redirect to it by redefining $link to point to your thank you page. That’s the easy way.

  13. i need add new link page….
    i have use it:
    // $link = get_permalink( $pid );
    // wp_redirect( ‘http://www.google.com’ );

    but not work and i see:
    “Warning: Cannot modify header information – headers already sent by…..”
    can you help please

    1. I’m unable to test for a bit yet….. you can try moving the get_header call up above the processing script, that may work better for an offsite redirect….

  14. Yes the problem is the header, but i have read in WordPress FAQ:

    “In case you’ve used the function: wp_redirect() or tried to use a header redirect after the header (or any content at all was sent) that error message will pop. Instead use javascript redirection if needed.”

    And the wp_redirect is the real problem, java script solution i need, can you help me?

  15. Oh yes!
    The easy way for work with your code is remove the validation php code (that not work correctly) and put the php engine form above the tag
    // <?php get_header()

    ONLY the PHP CODE

    add
    // wp_redirect( 'http://www.google.com&#039; ); exit; change URL with all you want
    after
    // $pid = wp_insert_post($new_post);

    USE FOR VALIDATE FORM AJAX SCRIPT

  16. no no it’s wrong!!!

    not remove validation and if put the php code above the //?php get_header() the image attached not upload.

  17. it’s incredible, all work correctly with my first solution but the images not upload if //wp_redicrect is in the script….
    i don’t know what i do….

  18. I use foreach through the terms assigning each a checkbox, but it doesn’t saves. Also need to use foreach code if adding another dropdown with another taxonomy, don’t know why, but works. I think problem is checkboxes can be a array and selects no :S

    1. hi! first thank you for the script!
      But I can’t use the redirection (and the validation verification for empty fields)
      I tried the Stew’s method for the redirection, but it doesnt work, I think I didnt understand the whole method :s If stew or someone could explain it to me it will be nice! :)

      1. ok i found a fidderent way for redirection and it’s working
        replace
        wp_redirect( $link );
        by
        echo “”;
        or for a different page
        echo “”;

          1. try again! =D

            replace:
            wp_redirect( $link );

            by:

            To a page
            echo "";
            To the created post
            echo "<meta http-equiv='refresh' content='0;url=$link'

        1. WP isn’t really set up to allow a lot of content in the comments. By default it’s pretty restrictive! I’ll look around for a plugin or a way to fix that. As for the redirect, as I have it above it works perfectly for me. I’m using it in that exact manner on a website. The redirect only seems to work if it is called before the header, otherwise you get error messages.

      2. Hi, for the validation, back on my first post about posting from the front end, I mentioned I couldn’t get the validation working either. I’ve gone through pretty much every tutorial on the web and nobody’s techniques work for me. I do plan to recode the whole thing and figure it out. Javascript would be a great for that, lots of tutorials around the google. But I do plan to redo my form as soon as I have some time. As for redirection, how does it not work? You getting errors, or what exactly is the outcome?

        1. actually if we dont touch your code, after submitting we go back to the form (empty) the wp_redirect is not used (due to the header) I saw a tutorial about a code ‘noheader’ to use in the form action, may be a clue…

          1. Ataraxia refresh not work in firefox, i have solve the redirect problem you can see my solution in old comment.
            Bye

    1. Well, nice idea, but I don’t know why do you have to use an array for your check box when a meta data would do just fine. I am working on similar project (a car sale website), but I am going for the easy way and it this point everything else beside the car made category all is based on meta data. After I will be thinking about using the giving data, another cat for car type, but anything not requirement more than two options will remain a meta data because I don’t wanna saturate the UI when I will be ready to translate it on the wp back end.
      Beside, It will be user friendly to have a message when the a user is not login.
      Everything else is very good and you keep it as simple as possible.

      1. I need to use taxonomies for this info, not metadata, so there’s no way to do so without coding this way. I don’t know how to use checkboxes :(

    1. Was having some database problems with my host that kept me from pruning my comments. I got rid of it now. Because of the word Voodoo used throughout my company, I get a variety of bizarre comments here and on my personal site.

    1. I’m glad you find useful stuff on VoodooPress! I wish I had more time to do a bit more. I’m really tied up lately with school and work. Hoping I can focus a bit more on cool new content soon, escpecially when WP 3.2 gets released.

  19. this is helpful post for me,
    my question, in create new post form how to change plain textarea with text editor (ex:tinymce)? i’ve tried several ways but not worked for me,
    thanks

    1. I have absolutely not been able to figure this one out. I worked on this with another person for a couple days. I was able to get the buttons to display….sort of. Everything was a mess. I’m not sure if any plugins exist with this functionality which you could look at the code for maybe?

  20. i was able to do a client side validation using jQuery and javascript. The submit button is disabled until all necessary forms are filled. I know, it’s not the right way to do it, but it’s something…

    1. Oh javascript is definitely not wrong! If you got things working in a manner you are happy with then your solution works! Many people use jquery validation, it was something I was considering doing!

          1. Thanks! im currently working on this for a site that still not online, im working on my computer. But im really close to finish it, so ill be posting the site here, soon.

  21. Hi, is it possible for you to send me copy via mail or ad a downloadlink, the code from the webpage gives me a lot of invisible characters when I copy it in to coda or any other text editor app, hundreds of these “[?]” I think that is the major reason why the poster post new entries for me. Thanks!

  22. Fantastic code snipplets!! Love it, had some problems earlier with hidden characters. (got hundreds of black diamonds with qestionmarks) That is resolved from your end by now! Thanks!!!
    Just like to tell that the form does not work on wp 3.2 with the twentyten theme. Don’t really understand why!

    Thanks again!!

    1. Really? I have a testing site on 3.2. I was almost certain the form was working when I tested after upgrade. Let me check it out when I have a few minutes to switch themes and add the form back in.

  23. The local site I tested the script on didn’t post from the form. When I moved the files to another install with a previous version it worked right away. Let me know how things are working on your end!

    Thanks!

        1. Yeah, Akismet had some issues. I think it may actually be my server, VoodooPress has been running really slow at times, and I’m getting timeouts, etc. when logging on from my home computer.

  24. Hey Rev. Voodoo, I found this post in wordpress answers (stackoverflow).
    Seriously this is the one I need. I thankyou very much for this useful article.
    Can you guide me to add one extra functionality?.

    I need like this. A group where user can duplicate the input fields.
    In your Example Lets take Your rating and that image upload button.
    I want them as a group. Below that group. I want a button to duplicate that group.
    So this is the group.

    I want them duplicated like this..
    http://www.coldfusionjedi.com/demos/jqueryadd/test1.cfm

    Source code of above example can be found here.
    http://www.coldfusionjedi.com/index.cfm/2009/2/19/Using-jQuery-to-add-form-fields

    I hope you will help me. Thanks

    1. You want to enter that as custom field for post or what?

      I can’t really understand what’s the point of that.

      You can add as much fields as you wish, you just need to run loop to input all that in your new post array.

      1. That would definitely be meta boxes/custom fields. Looks like the point is that the end user on the front end is able to duplicate fields as needed, rather than the developer guessing how many fields are required and hard coding it.

  25. For a minute after reading the title, I tough this would be about reviewing the post (making changes) from the front end. I really wouldn’t hope for better than been able to modifier post filled from front end without login in the admin area.

    1. You can see my reply to your other comment. So far, I haven’t really had time to look into this too much. It’s definitely something I’d like to get done though.

      1. By the way could you point me in the right direction of how to deal with subcategories and parent categories? supposed I have 2 select forms of parent categories and subcategories.
        How could I manage to have the subcategories select form populated automatically when the parent category on the first select form is been selected. All this without page refresh, I guess there has to be some jquery or ajaax involved.

        1. I’ll try to find an old tutorial I used before. It was a fairly simple ajax script that allowed for picking subcategories. The subcat dropdown populated based on the parent cat selection. I don’t have the code in place any more to copy out for you, I’ll see if I can’t find that tut that I used.

          1. Thanks for the heading, I also found a tutorial about it (http://wpguru.co.za/navigation/creating-a-dynamic-select-menu/), but I just found out it will not be an economical way for me with my project. it will be hundreds entries with car makes and models combined. The approach will like to know is how can I let the user input the make as the parent category and the model as the child if he can find his on my list? and still at this point I can’t figure out how to implement any of this with your fond end posting.

    2. Actually we’ve done that.
      My colleague just made some small theme, actually it’s shame I can’t show you how that looks because you need to be logged as admin in wp, and then you get just 2 buttons on side edit and save.
      Every bit of site is editable and editing is done live with just click on edit and then on text. Works with uploads, texts, shortcodes, etc….
      It’s quite a jQuery beast, I think it can be done for whole wordpress, but we need something that we don’t have atm… time…

      this is just the screen-shot how that looks.
      http://imageshack.us/photo/my-images/808/screenshot20110802at924.png/

      1. That would be awesome! Unfortunately, jQuery is not my area of strength. I just haven’t had the time to spend on it as I should. I would love to dig in a little deeper, but while I’m still in school, that ain’t gonna happen!

      2. Would you mind sharing the code with us here? I have been looking to this for ever. This is the only thing keeping me from dumping every single plugin out there. It will be a heaving to let my users (clients) manage their site (posts) without seeing the back end.

  26. Love this, very helpful! Is there a way to get the data to save in columns that are a part of the wp_posts table? Right now things are split between a wp_posts table and a wp_postmeta table, and the wp_postmeta table post items are scattered across multiple rows vs nice columns… Or even if I could somehow save all of this data across multiple columns in a new table that would be amazing! Any ideas here? I am working on a non profit child sponsorship website and could really use the help, Thank you!

    1. Well, this is set up to work exactly as WP posts do. Which is why things are split up like that, it’s the same as using postmeta in actual posts. You could probably save all the values within a single key, and pull them back out with a foreach loop.

      But for what you are looking for, you can, of course save things as you wish in your own table. I haven’t yet started working with that, but let me point you to some links. When I get around to doing this, I’ll definitely write a tut about it. But until then:

      http://codex.wordpress.org/Class_Reference/wpdb
      http://wptoy.com/tips-tricks/create-a-plugin-with-its-own-custom-database-table/
      http://www.wpmods.com/tag/wpdb/
      http://wp.tutsplus.com/tutorials/advanced-wordpress-queries-part-1/

      So working with the wpdb class will be your friend here. I’d love to hear back from ya if you wade your way through this!

  27. One other question for you…. Do you know if there is a way to incorporate these fields into the back end? The issue is once you have this information entered how would one go about making a change to it?

    Thank you!

    1. Which fields? Everything here gets inserted into a post. So it is available to edit from the backend as normal. Title, tags, post, cats, etc. Even the meta data will show in the custom fields section, as long as you don’t preface the key with an underscore.

      1. Ahh, how right you are… It was simply a matter of displaying the Custom Fields in the Screen Options on the back end of wordpress… Thank you and sorry for the mixup :/

    2. You would have to make some sort of custom solution I would think. The backend is only going to see standard WP stuff…. if you are making custom jobbies, using custom DB stuff, you’ll need a custom backend form which brings that data in..um… customly! ;)

  28. I have tried to let authors register posts in category and corresponding subcategory, but it’s a mess having to select option with the second based on the first has it parent category.
    Now I have ether the option of making it easier on me by letting them input their own category and subcategory in case that the parent category will be “makes” and the subcategory will be “models”. it will be prone to errors, but at least I won’t have to pre-populate the category and subcategory with hundreds of input. by the second choice will be to have a unique select option where there are categories with their child categories. for example a category make of Honda will have underneath child categories of civic, crv, etc.. and only the child categories can be selected which is diminish errors.
    Could anyone direct me on how to make such option works?
    I found this tutorial (http://wpguru.co.za/navigation/creating-a-dynamic-select-menu/) about having 2 select option search and I will probably use it on my project, but the question remain how to let author choose their subcategory without me having to populate the database first?

  29. Using the code as specified… I’m getting the following error:

    Error: Form elements must not have name or id of “submit”

    Removing the name/id on the submit button makes the form non-functional. Form works fine when cf7 is deactivated. Why the conflict, as it sounds like you’re using this code successfully with the plugin?

      1. I see. I thought you were piggybacking on cf7 for alerts/validations and things. This form you have doesn’t have any sort of error messages or success messages like cf7 does, then? Thanks for your response!

        1. Nope, I don’t use any alerts. In one of the comments threads in this series, we discussed using jquery. I also have a bit of php in there that doesn’t work. But I have made a note of a possible change in one of my posts in this series. One of the readers showed a simple code change that should fix the php alerts, I just haven’t tested it.

  30. This is awesome. Thanks to all who have contributed.

    Has anyone else been able to add excerpts to this form? It’s driving me nuts, but I can’t get this to work. If I add “post_excerpt” to the array and give it a value manually, works fine. However, when I try to create a text area and pull that in, the excerpt is being left blank. Is there something else in the code I need to do? The bits of code I added are:

    'post_content'	=>  $excerpt,  //added to the new_post array

    and

    <!-- post Excerpt -->
            <fieldset class="content">
               <label for="excerpt">Excerpt:</label>
               <textarea id="excerpt" tabindex="17" name="excerpt" cols="80" rows="10"></textarea>
            </fieldset>

    Thanks for any help you can provide.

      1. Yes, sorry. Typo. Is it correct otherwise? I’m a hack at PHP as best, so I was just copying what you had for the content stuff.

  31. Hi there,

    ive been working with this but it seems to be baffling me slightly. I’m trying to get the $newupload into a custom field attached to the post like the rating is doing but i’m having trouble. i’m hoping to be able to show the post id and the attachment id in the post when the post has been submitted but also able to pull the attachment id out of the post for use with another plugin i am currently using.

    would this be an easy task or will it take a lot more coding as i’m scratching my head now!

    Oliver

    1. Would it work if we just add 2 more add_meta lines near the existing one, line 40-something.

      add_post_meta($pid, 'postid', $pid, true);
      add_post_meta($pid, 'attachmentid', $newupload, true);
      

      No idea what that will turn out, but I’m gone for the weekend…wanted to try to throw something out before I head out!

      1. Ive tried this and got the post id now added to a custom field and a blank attachment id field, this is the bit that is baffling me!

        thank you for the quick response and the help

        1. Ive managed to solve it!
          i just inserted the

          add_post_meta($pid, 'attachmentid', $newupload, true);

          into the media handling part of the code

          	//INSERT OUR MEDIA ATTACHMENTS
          	if ($_FILES) {
          		foreach ($_FILES as $file => $array) {
          		$newupload = insert_attachment($file,$pid);
          		add_post_meta($pid, 'attachmentid', $newupload, true);
          		// $newupload returns the attachment id of the file that
          		// was just uploaded. Do whatever you want with that now.
          		}

          and its posting the attachment id into the post custom fields like magic!
          thank you for this wonderful script and an easy tutorial to follow

          Oliver

  32. Thank you so much, this script has really helped me out and it’s a lot better than a lot of the plugins out there!
    Oliver

  33. Hi,

    I am trying to use your code for allowing users to create post (with images) from the front end.
    Everything seems work well, except for the upload and visualization of the image. This doesn’t work!!
    I am using the Custom Community theme (from themekraft)…

    Do you have any suggestions of what it might be not working…?

    Thanks in advance for you help, and any kind of tips you’ll give me…
    Valeria

    1. I have no idea without seeing the code in the context of the theme. Does your image even upload/attach to the post, or is that not working at all? The good news is that WordPress 3.3 will be released very soon. That release is going to allow for us to use the native WP post editor and image uploader from the front end. So I hope to get a new tutorial up once that happens which will be simpler to use.

  34. Hello, thank you for the code. Could you please tell me what I need to do if I want to select categories with the checkboxes. I have three categories and want to let the user to select in which categories he wants to publish the post instead of dropdown.

    Thanks in advance,
    Sinisa

    1. Well… you would need to grab the categories, and loop through them, outputting your checkbox with each cat. Off the top of my head, I would think we could replace line 95 above with something like:

      <?php
      $categories=get_categories();
      foreach($categories as $category) {
      	echo "<input type='checkbox' name='mychecky' value='$category->term_id' />";
      	echo $category->cat_name;
      	echo '<br>';
      } ?>
      

      I think that is right. Outputs the cat ID to the value, but echoes the readable cat name to the user. YOu may have to play around a bit…. it’s early and I may have a dumb error here….

  35. Thanks for your code! It’s very good even though I had some difficulties in the beginning. For example, if I wanted to use the class from contact form 7 for some reason the form would simply not work, so i got rid of that class.
    It would be cool to add a preview button :).
    Thanks again!

    1. I use the classes from cf7 myself and it works. I think the trouble is with the submit button, and cf7’s processing script. I believe the reason it works on my site is that I stop cf7 script from loading on pages where there is no contact form, like this http://vudu.me/4o. Also, when WP 3.3 gets released, there will be a new API for using the WP editor in the frontend. I think that might make a preview feature much easier to set up.

        1. Yeah, me neither. It looks like we’ll be able to do image uploads the normal way and everything. It should cut down on code, and make the whole posting experience so much simpler!

  36. Is it possible to add a date picker to set the post’s date? For example if we want to publish posts 2 weeks in the future, or even for later that evening.

    1. I’m sure it would be. http://codex.wordpress.org/Function_Reference/wp_insert_post
      You can see there in all the available fields, you can assign a post date of future, which then requires a post_date to be set. If the form would be used for future or immediate posts, that could be tricky. Requiring code to either check the input date, and select publish or future, or hiding the date picker depending on if publish or future were selected. Probably take some jQuery magic, not my area of expertise at all.
      http://www.w3schools.com/html5/html5_form_input_types.asp
      html5 supports a date picker. Wouldn’t be too hard to implememnt maybe, but limited support. And of course jQuery supports it…

  37. Hello Rev. Voodoo! Thanks for your tutorial!

    There are some problems, when I’m submitting empty form, I’m getting below error:

    Please enter some notes
    Warning: Cannot modify header information – headers already sent by (output started at E:\xampp\htdocs\ftbl_dev\wp-content\themes\ftbl\header.php:18) in E:\xampp\htdocs\ftbl_dev\wp-includes\pluggable.php on line 866

    Code of my header.php – http://pastebin.com/kLkCvqSn

    Thanks once again!

    1. I’m not sure… but you have it set up in a manner I’ve never used it. I would try to pinpoint where the problem is. ONe of the flakiest things is the redirect… I had tonnes of problems with that. Try commenting out line 43 the wp_redirect and see what happens. Just to see where the issue lies. There are a variety of things that could be acting up here using this code as header.php, not sure if I’ll be able to nail it down….

  38. I need to add two separate front end post forms. One to register businesses and another to create events. I have the forms figured out, but I cant figure out how to force a category for each form, instead of letting the user choose.

    I’ve created two separate categories, and I’d like to force all posts made with the business register form to be placed in the “Businesses” category and all the posts made with the events form to be placed in the “Events” category.

    I’m sure this is simple, but I can’t seem to find the documentation that tells me what to put in the place of your drop down.

    <?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>

    I’d like it to be a hidden input, so the user doesn’t even see it happening.

  39. Hi. Really great script you wrote. Now my problem. I would like to save the post into several categories? How do I have to change your script?

    Geschlecht:

    Farbe:

    I want the user to choose a category child_of 8, then choose a category child_of 61 and so on… Actually the post is posted into the last category chosen. I hope you get my problem… You would help me out…

    Thanks.

  40. Sorry, I didn’t post my code…

    ><tr>
        <td><fieldset class="category"><label for="cat">Geschlecht:</label></td>
        <td><?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0&child_of=8' ); ?></fieldset></td>
      </tr>
      <tr>
        <td><fieldset class="category"><label for="cat">Farbe:</label></td>
        <td><?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0&child_of=61' ); ?></fieldset></td>
      </tr>
    
    1. So you want a user to pick a cat from each of those dropdowns, and assign the post to each? I’m wouldn’t be 100% sure on how to do that without setting this code up on a test site again… I don’t currently have this set up anywhere. We just need to feed each cat into the array. So my initial attempt would be to leave the first dropdown as cat, and the second dropdown maybe change to cat2, and then in the processing code add both into the array:

      //something like this
       'post_category' =>   array($_POST['cat', 'cat2']),
      

      I’m not sure that’s right, but it’s where I would start….

  41. Got this working perfectly apart from one ting I cannot for the life of me get working ….

    Rather than the dropdown be populated by categories I have it populated by terms of a custom taxonomy.

    I have tried changing the post_categpry where it says // Usable for custom taxonomies too but the post will not save and check mark the correct term in this custom taxonomy in te backend when I view the draft

    How do I save the post so that when I view it the correct taxonomy terms has been marked????

    Please help is the last things I need to do before sign off!

    Thanks in advance

    Regards

    John

    1. Ya know, I haven’t tested this with a custom tax. That was copied from one of the many tutorials I had to piece together to get this working. http://codex.wordpress.org/Function_Reference/wp_insert_post

      Check this out for things which can be set through wp_insert_post. I’m wondering if using tax_input works for custom taxonomy? I’m going to research this a bit more, but was hoping I could help guide you in the right direction to experiment.

        1. Thank you! You sent me in the right direction and I can confirm this works. Simply replace:

          'post_category' =>   array($_POST['cat']),

          ie, line 28, with the following:

          'tax_input' =>   array ('wine-category' => array($_POST['cat'])),

          where “wine-category” is the name of your custom taxonomy as you registered it.

          Hope this helps any future Googler’s. =)

  42. Hi, I really liked your Front End posting form. I am using it on my website…it is the final solution I was looking for. Perfect one. Using that front end form, our site users can post it without formal registration process.

    Recently, I have some problem with the spammers especially with the Bots. They are recognizing the front end posting form as a comment form and filling every details and posting it. Thats pain in bottom. Each time we have to manually delete the posted entry.

    I think the solution to this is to use “HoneyPot captcha”. I have looked around and found its been used in several contact forms. I wish is there any way to include it in your Front End posting form. What do you say! If yes, I would really welcome an updated form of your FrontEnd or a short code or tutorial on it.
    Cheers

    1. I agree that some sort of checking needs to be done on this form! Right now, it is pretty wide open, and allows anyone to post! I won’t be able to include any form of captcha however. I simply do not support their usage on any website, for any reason. I don’t want to be all preachy, but if you are interested you can google for captcha and accessiblility. Captchas are just not good for many internet users. Also, they can be bypassed fairly easily. I would like to do some better verification on this form at some point, I just haven’t had any time lately!

      If you truly want to get a captcha going, it shouldn’t be too hard to figure out from the Google machine! I’m sure there are plenty of tutorials.

      1. Hi, thanks for reply… Actually, like you I also dont like Captchas. Thats why I am avoiding it until now. I personally think that its better to have a HoneyPot captcha (for bots) than to have captchas or Recaptchas with a word hard to read etc.
        I am really looking fwd for a strong validation method for FrontEnd posting on your form. But, in the mean time, can you suggest something which could solve “especially the Bots spam” :-).

      2. Ok, I found some tutorials about HoneyPot captcha, but literally all of them are for contact forms.
        With my limited understanding and knowledge I tried to copy the selective Captcha fields and used it in the Rate-Wine form for Front end posting.
        It resulted in nothing. I mean after pasting codes in the Rate-wine form I am unable to render the form itself. Literally nothing is loaded (Only blank page). Means I am unable to paste the code at right place. If you dont mind suggesting me where can I put which portion of the code in Rate-wine form it would be a great help. I am refering this tutorial which used it for contact form: http://devgrow.com/simple-php-honey-pot/

        Cheers

        1. Yeah, it’ll take a little looking into to get the processing working properly with what we already have. This technique is user friendly, so I don’t mind getting it working. Hopefully I can find some time soon to make it work, I’m pretty tied up with school and work right now.

    1. Nope, I had actually forgotten, sorry about that! I only had 1 week off between quarters at school, and this quarter is really rough. Hopefully I can find time to look at this.

  43. Hi,
    Good news! I finally solved this honey pot captcha (HPC) on my own…feel free to visit http://posterpie.com/ to see it in action…… I must say this was literally nothing……. not even a 10 min job for a coder. I found the solution by placing the HPC validation code before your “if” statement and thats it! However, still the image attachment is an issue, but I think you can see it when you will have time….

    Cheers

      1. Like you I also dont like Captcha but had to do something for these stupid bots at the same time keep the visitors happy. Now things are ok, but I just realized that if somehow the HPC field is visible to humans (due to browser issue or anything) and if any visitor will fill that field and try to post then post will not be posted but the image will be submitted to the database (media library). I want that site should not accept anything from the user in this case. I think this is too much for me and I am not a code expert. May be if you have time to look into it (I think we need to again put somewhere where the code validates image attachment “if isset” statement and related to the HPC field) then I wont mind taking that bit of code too :-)….

        Just give it a try when you have time…..

  44. Hey thanks for a great tutorial. I was playing around with some form validation and want to make the uploading of the image mandatory. Any ideas or examples of the best strategies to make this happen with your script?

    I am using the below code to validate mandatory fields such as ‘Title’ and ‘Description’ but still can’t figure out what do for the image? Any ideas? Thanks again…

    // Form Validation
    $required_fields = array(‘title’, ‘description’);
    foreach($required_fields as $fieldname) {
    if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
    $errors[] = $fieldname;
    }
    }

    if (empty($errors)) {
    // Execute Voodoo’s Script To Save Post / Upload Image
    }else{
    $error_message = “Please fill out all fields.”;
    }

    Any ideas how to incorporate making the image file mandatory? Thanks again for a great tutorial!

    1. Hi David, Do you want this code or you dont mind working with java script? I am using javascript for image attachment validation…… well you can check it on my site and decide if you want php validation or javascript?

      1. Hey PosterPie, rad site. I would prefer php since I am doing the rest of my site and the validation in the same way. It would make displaying errors for my users a bit easier. I tried to apply this code for validation:

        if(empty($_POST['image'])) {
        $errors[]=”Please Upload An Image”
        }

        if (empty($errors)) {
        // Execute Voodoo’s Script To Save Post / Upload Image
        }else{
        $error_message = “Please upload an Image.”;
        }

        But this did not make uploading an image mandatory. Do you have any better ways to implement php validation for required upload of an image? Thanks again.

  45. So i created some Javascript validation. In the header put:

    <script type="text/javascript">
    window.addEventListener?window.addEventListener('load',validateForm,false):
    window.attachEvent('onload',validateForm); // FF : IE
    
    function validateForm() {
    	var frmBase = document.getElementById('new_post');
    	frmBase.onsubmit = function () {
    if (!this.elements['human'].value.match(/^Black/i)) { // If value is not a digit and length should be 10
    			alert('Please check if you are human.'); // Let the user know
    			this.elements['human'].focus(); // Set the foucs
    			return false; // Cancel any event from this point forward
    	}
    }
    </script>

    Then add another form field at the end like:

    			<fieldset class="human">
    				<label for="human">What are blablah blah?</label>
    				<input type="text" name="human" id="human" tabindex="30" />
    			</fieldset>

    This will work.

    If you want to do it the php way change:

    if (isset ($_POST['title'])) {[php]
    
    to something like:
    
    [php]if (isset ($_POST['title']) && !empty($_POST['title'])) {

    This will check a field is not empty, it could also be changed to equal a string.

  46. Hi! I think the 3.2 wp update has changed something. The image upload is causing a warning when the form includes null file inputs: “Warning: array_unique() [function.array-unique]: The argument should be an array in [...]wp-includes/functions.php on line 3188″. I get this only when only some (or none) of the image inputs are entered. When all image inputs are used then no error. I thought that the foreach isset would take care of any empty inputs but no dice.

    This is an old post so I’m taking a shot in the dark. Regardless, its a very helpful post, thx!

    1. It wouldn’t surprise me if something changed with regards to the media uploads… either WP 3.2 or 3.3 (or maybe both) had introduced several changes to uploads. I’m not sure when I’ll get a chance to revisit this form, I’d love to get it updated – I’d really like to include the native WP editor and media uploader since those are now available from the front end…. I’m just super tied up with school and work for the near future.

  47. hi there

    would like to know how to make the post format selectable, like a dropdown box to display the post formats. I’m busy setting up a website for my wife (using a twentyeleven child theme) which uses standard, aside and image post formats. so i would like the post formats to be selectable on the frontend.

    many thanks for your great tutorials.

    1. I’m super busy right now, and having a hard time doing much of anything. Hopefully I can at least get you pointed down the right road. For your purposes, the most important thing to know is that post formats are just a fancy taxonomy. So if you can figure out how to work with cats, or tags, you can pull this off.

      http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
      If you check out the last example here, you can see that we can query posts by specifying taxonomy->post_format and then the terms are post-format-$format

      So you should just be able to populate your selection with the taxonomy and be good to go! Hopefully I can revisit this shortly, but I have a heck of a work and school schedule right now!

      To be able to use the formats (and keep them friendly looking in a dropdown) we’d probably have to have the value be a nice human readable ‘Quote’ and then us the name of post-format-quote or something… I’m on my first coffee here, so I haven’t thought this all the way through. But I hope you can at least get started with that info

      1. Thanks for the info. I’m quite a newby to wordpress. I’ve tried a couple of things, but it is all bad news. I will be happy if you can help me at a later stage as soon as you have time on your hands.

        I’ve already learned a lot from all your other tutorials.

  48. Fantastic post! Love it. It almost works for me, there is just one thing left, I want to add the URL of the file I just uploaded to save as metatag. Also, I want to display the chosen category, but when I take the $_POST[‘cat'[ I get the ID of the chosen category and not the name.

    I hope you guys can help me out.

      1. - Ok
        – Yes I want it to display the category name in the post (actually in a metatag but comes down on the same). I checked some things out here but still can’t get it to work. So I can display the category ID but not the name.

        Thanks.

  49. Nice Tutorial to make a custom form. I have a question, if I leave custom field value empty, it adds the meta_key to the post with blank value. How to ignore the meta_key from adding to post when the field is not filled in the form?

    1. You can do that by a simple php check.

      $field = $_POST['field'];
      if ($field != '') {
      add_post_meta($pid, 'meta-tag', $field, true); 
      }
      
  50. Hi there,

    thank you very much for your nice tutorials. All is working fine for me, except one problem with another Plugin.

    If I upload an image as thumbnail and nextgen-gallery is turned on, I get the following error message on the edit (custom) post screen in the post thumbnail box:

    Catchable fatal error: Object of class WP_Error could not be converted to string in /var/www/web1/html/gassiservice/wp-content/plugins/nextgen-gallery/lib/post-thumbnail.php on line 50

    Here are the lines surrounding line 50:

    // in the case it’s a ngg image it return ngg-
    THIS IS 50 => if ( strpos($thumbnail_id, ‘ngg-‘) === false)
    return $content;

    // cut off the ‘ngg-‘
    $thumbnail_id = substr( $thumbnail_id, 4);

    return $this->_wp_post_thumbnail_html( $thumbnail_id );

    Maybe someone could help me out.

    Regardings

  51. I’ve been using SEO Ultimate and I want to include its title, description and keywords fields in the form. I tried adding the following code in the array(

    'title_single'	=>	$post_title,

    but it doesn’t work, does anyone know how to include SEO Ultimate title, description and keywords fields in the form?

  52. I have a simple php form which has the following function: –

    <?php
    if(!empty($_POST['middle'])) {
       echo "a sentence".$_POST['middle']." with something in the MIDDLE.";
    }
    ?>
    <?php
    if(!empty($_POST['end'])) {
       echo "a sentence".$_POST['end']." with something in the END.";
    }
    ?>

    Now I want to include it in the form and I did it using the method below: –

    if(!empty($_POST['middle'])) {
    $description = 'a sentence ' . $_POST['middle'] . ' with something in the MIDDLE. a sentence ' . $_POST['end'] . ' with something in the END.';

    but it will ignore the whole value of $description if the field of ‘middle’ is empty and I want it to ignore just the first sentence if the field of ‘middle’ is empty and display the second sentence having the field of ‘end’ i.e.

    'a sentence ' . $_POST['end'] . ' with something in the END.';

    How to make it work like this?

    1. There are different ways to do something like this, here’s one of them:

      if(!empty($_POST['middle'])){
      $descriptionmiddle = 'a sentence ' . $_POST['middle'] . ' with something in the MIDDLE.';
      }
      
      if(!empty($_POST['end'])){
      $descriptionend = 'a sentence ' . $_POST['end'] . ' with something in the END.';
      }
      
      $description = $descriptionmiddle . $descriptionend;
      

      Another way could be:

      if((!empty($_POST['middle'])) && (!empty($_POST['end']))){
      $description = 'a sentence ' . $_POST['middle'] . ' with something in the MIDDLE. a sentence ' . $_POST['end'] . ' with something in the END.';
      }
      else if ((empty($_POST['middle'])) && (!empty($_POST['end']))){
      $description = 'a sentence ' . $_POST['end'] . ' with something in the END.';
      }
      

      Is this what you’re looking for? As I said there are many more ways to do this.

  53. I was thinking that having a rich media embed functionality would be good. But I’m not sure how to do it. Basically, users would types in a url and then the media (image/video) will be detected; very much like facebook when you add a link to the status update.

  54. Hi. Thanks for the awesome plugin/code you wrote for people to post stuff from the front end.

    But I need help. I can’t get it to work. That code that needs to be inserted above the get header tag is nog displaying on my template for some reason. But the form is displaying.

    My url is http://www.pffft.co.za/submit

    Would you mind having a look please or do you know what the problem might be.

    I used the code from this page http://voodoopress.com/review-of-posting-from-front-end-form/

    Thank you in advance

  55. The form works great but i cannot get it to work on my multi-site, anybody have any IDEAS?????
    works fine on my localhost testing

  56. Hello. Thank you for this awesome code. It is ideal but there is one necessity. Please help me to be able insert images in post content (embed). How to do this.

  57. Hi! Thank you very much for your tutorial! I just want to ask you or anybody else for little help about uploading files. Is there any possibility to change uploaded file name for post number (ID)?

  58. Hi Bro,

    Great tuto ! Many thanks!

    I have a little problem with it. The problem is that when I use the_content(); it put the thumbnails and the featured image in my post or I didn’t put the thumbnail in the wysiwyg… Any idea?

    Cheers,

    Jhon

    1. I had queryed the VoodooPress users hoping someone would come up with a great way to do that! I just use Gravity Forms now, simply because I’m too busy to keep working on this code. I was really hoping areader would further develop this starting point we have here!

  59. Hi,
    I am not sure, will you reply me or not.
    First thanks for this post, it really helps me alot. I just have a question, I am not sure how to explain it,, How to submit post format as a gallery. If you do’nt set format of post it will use standard format. But i want gallery format for my post in this front end form.
    Thanks in advance.

  60. I’ve tried submitting the form as ‘preview’ and the posts just show up as a draft. I am wanting to use a plugin that notifies me of pending review posts by email but can’t get the email notification to work unless the post is marked ‘pending’. Is this line correct with the options?
    ‘post_status’ => ‘publish’, // Choose: publish, preview, future, draft, etc.

    Also I have been working with no luck to get the form to save the data on error and have had no luck. Do you know of a solution for this. I’ve tried some methods that I have found from other websites but must be missing something as none work with this form. Other than that the form works great.

    Thanks in advance for the help!

  61. Does anyone know how to get the url of $newupload in:

    foreach ($_FILES as $file => $array) {
    $newupload = insert_attachment($file, $pid);
    }

  62. Awesome tutorial, I am newbie to wp and you helped awesomely.. Many thanks

    I’ll using these techniques in my personal accounts site.. will post link here for sure…… :)

  63. I’ve used your articles to write my own form very successfully – thank you. But I now want to use a simple captcha question for added security. Any tips?

Leave a Reply