42 Replies to “Add a Meta Box to Use Custom Fields on Front End Post Form”

  1. hello give me error in this line
    ‘winerating’ => $winerating
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)’

    1. Did you add the comma to the line above as I mentioned?
      If you add a new line to the array, you must add a comma to the line above, every line has a comma after if, except the last line, which would be your new winerating line

  2. thanks your tutorial is awesome, really.
    i have only one problem now, when i send the form i see this

    “Warning: Cannot modify header information – headers already sent by (output started at C:xampphtdocstestwp-contentthemesdailyblogheader.php:4) in C:xampphtdocstestwp-includespluggable.php on line 897”

    maybe the problem is the local server?

    1. Hmm… often times that error is due to some blank space before or after a php opening or closing tag somewhere. It can be hard to track down….

      Like if you made a page template, the opening php tag has to be right at the top. And if you close a php tag, and then reopen it with no html in between you shouldn’t have space. functions.php is especially sensitive to this, but it can happen anywhere

  3. argh…!! i think that the problem is the xamp server…maybe!

    Only one think for this tutorial…
    – How i can add redirect page after submission post (draft)?
    – How i can allowed only register user to add post?


    1. I found the problem with the form…

      wp_redirect(get_permalink($pid)); exit;

      this redirect is causing the errors…..delete it and the form works. I’m going to work on a better redirect

      1. Ah Hah!!! Got it. Basically the form processing block of code needs to go up at the top of the code. Like below the page template header, and above the get header call.

        Once the code is moved there, all is well! If you don’t quite follow what I mean, I’ll be posting full code tomorrow.

  4. hello i have test to add only this
    echo “”;

    where ‘link to redirect page’ is the page that show after submission form, it’s work good when submission is set to ‘draft’

  5. Hello and thank you for this information!

    But . . . I am stumped as a newbie WP themer. Where do these snippets of code actually go? I’ve read many different versions of this basic implementation — add meta box to blog post form so user can add images (or whatever) to the post. But I don’t understand quite where to actually place the code — in the functions.php file? in the post.php file? in the loop.php? Your help is really appreciated!

    1. My apologies if that is not clear from the series of tutorials. If you are following this series, then all the code goes into the actual template for your post from front end form. That may be a little more clear here:
      Where we review all of the code. Normally meta box code goes in functions.php, and we have other tutorials on this site about that, but these particular ones for use in a ‘post from front end’ form go into the actual template.

  6. Hello,
    very good tutorial! Thanks!
    I would like add meta select field (ex Select your country) and also meta checkbox field? Can you help me please?

    1. I’m glad you found the tutorial useful! Thanks for taking the time to comment, and also for leaving a request. I like getting suggestions for useful articles. I will try to get something up today that covers dropdowns, chackboxes, and radio buttons.

    2. I posted a new tutorial explaining how to use dropdowns, checkboxes and radios on a front end post form. I was trying to do the same from the backend which proved difficult. I stumbled across a very cool meta box ‘framework’ bit of code that is very helpful, I plan to be posting about it soon, so check that out if you need more meta box options on the backend.

      1. Thanks for your reply. What I’m actually trying to achieve is a wiki-like dictionary. Thanks to your tutorials, I’ve been able to lay down the foundations for a contribution form with extra information per term (such as translation and external links).

        The idea is that this would be a web app, that users could log in and add terms, and others could edit them later. The reason I haven’t chosen mediawiki is because of wp’s custom fields (and mw sucks).

        Am I clear enough? Any help would be greatly appreciated.

        1. The wiki thing is something I haven’t looked into. It would seem that you would want to allow some sort of front end editing then correct? I haven’t been able to get into that yet myself. I plan to get working on that for another site of mine, I’ve just been tied up with school and work. I’m not sure if any of the WP wiki plugins are good enough for you to at least peak at the code and see what they are doing.

      2. By the way, is it possible to add multiple values per field? Following my example, I want users to be able to add multiple values for a filed for external links.

        1. My site using my post form is AWOL right now pending additional work. I may reset it so I can test. So the issues with multiple values in the field is that they all get stored as one line in the DB pretty much. Does the meta box allow for the multiple entries? If so, then the next issue is getting those individual lines back out to work with. I had to deal with that once, http://vudu.me/f7 is how I was able to seperate out the values.

          1. That might work, from glossing over it, I’m not sure if you can use it from a front end form. At the beginning though, it’s basically showing the same technique I gave above. Running a foreach loop to grab the individual values out of a single meta entry. If it’s able to be utilized on the frontend, it could make things easier for sure.

  7. Hi,

    Love the tutorial, very detailed, I was wondering if there is anyway that the person filling in the form could see a preview before actually posting. I know that
    they see the page once the form has been submitted.

    1. I haven’t been able to figure out a good way yet. A few of us have been looking into a preview. It gets especially hard when trying to preview an image attachment. The images and the custom fields I are tougher. I haven’t had a lot of time to throw at this, I would love to figure out a preview and an edit from frontend soon….

    1. On the back end? It should just show up as a post. Editable through the admin like normal. Front end editing I haven’t figured out yet…. Definitely a goal of mine though.

  8. Thanks for getting back to me thats brilliant, I was wondering if it would be possible to put a delete button on the post for the first view only as a workaround, that when clicked deletes the post and takes them back to the form. I found a great delete post from front end function.

    1. I’m sure I can come up with a delete function. However it would be limited. For instance, I let anybody fill out my form, including unregistered users. I don’t know how to allow for an unregistered user to delete their own post. Reason being, in WP unregistered users have no user level. The delete button would only work for people allowed to delete the particular post. So it woud always work for an admin or editor (I believe), whereas a contributor would only be allowed to delete their own post.

  9. Thanks, any kind of preview would be appreciated, but in retrospect probably not as important as I first thought. I could simply ask posters to carefully check their entries.

  10. There is a way, but I didn’t go that way when I used front end posting, if someone entered something wrong he’ll have to do that again and inform admin about mistake.

    Set post as private and redirect user with some level of privilege to it, then he can confirm it’s on or not what sends post to draft/publish (if you want to check with admin too) or trash if he doesn’t like it.

    But security is something to consider here. You’ll have to check that he’ll stay only on that link… It can be done in theory but honestly haven’t tried it myself.

    1. Ya, I haven’t messed around too much yet. Security is my biggest concern. I don’t want to give any advice on VoodooPress which can allow for someone’s site to be vulnerable.

  11. Solid tutorials here, thank you very much for taking the time to help add this great functionality to WordPress. I’ve done three so far with no issues on WP 3.3. I was expecting some, but so far, flawless.

  12. How create single custom field with textaera on specific page? Eg: i trying to do, current author can edit their Bio Info in front end? or using custom bio info. then i can gab the value/their text area fill to show.

    Please reply or do tutoial bro

  13. how can i add multiple images to my meta box ..from front end form ,by using your tutorials currently add one image to meta box …i want multiple , please help me out.

Leave a Reply