Hi, first of all, I’d like to say great work on this plugin.
I am just wondering how I would make it so that the Username of whoever submits the form is the Post Title?
I am comfortable changing the code also if that’s what I’ll need to do. Just need you to point me in the right direction.
Thanks
Alright, haven’t had any luck with it yet.
What file specifies that the default Post Title is set to the current date?
Could I just simply replace that with something like which I think woud include the submitters name?
I am not too familiar with Wordpress Codex, so am I even heading in the right direction?
With v0.12, there is a new, possible nicer way to do this without so much hacking. Add an “Append to Post Content” widget to the bottom of your form and then add this piece of code:
<?php $title = false;
if(is_user_logged_in()) {
$title = "%%USERNAME%%";
} else {
$title = get_post_meta($post_id, TDOMF_KEY_NAME, true);
}
if($title != false) {
$postdata = array(
"ID" => $post_id,
"post_title" => $title );
sanitize_post($postdata,"db");
wp_update_post($postdata);
} ?>
This should modify the post title to be either the username or the submitted name of the submitter. as long as it happens after all the other widgets, this will be the title of your post!
I’m having trouble with this code… I’m trying to set the form to always / automatically use the submitter’s name as the post title. (I’m not using registrations or comments on my site.) The 0.12 “Append to Post Widget” code doesn’t appear to be doing anything for me – the post title is blank.
Any help you can provide would be greatly appreciated!
The code worked for me on my test site no problem. If you don’t allow registered users, you could probably shorten the code to something like:
<?php $postdata = array(
"ID" => $post_id,
"post_title" => get_post_meta($post_id, TDOMF_KEY_NAME, true) );
sanitize_post($postdata,"db");
wp_update_post($postdata); ?>
I assume you've made "Name" on the Who Am I widget required? I'll double check that the code is okay.
Bugger. I discovered a bug that would break this widget if you’re not logged in. Which is why the code is not working. I’ve fixed it, and you can grab the updated version from SVN here (before I make an official release).
BTW You can use this simpiler code too:
<?php $postdata = array(
"ID" => $post_id,
"post_title" => "%%USERNAME%%" );
sanitize_post($postdata,"db");
wp_update_post($postdata); ?>
Tried your code, and the “Submitted by USERNAME” didn’t show up in the submitted post, so it looks like there’s an issue with the “Append to Post Content” widget.
“%%WIDGET:append-1%%” is being called in the Form Hacker, so not sure where the issue is.
Thanks again for your help on this – you’ve been fantastically responsive!
Could you open your copy of include/tdomf-msgs.php and see what is at line 57. You should see seomthing like this:
$message = preg_replace('/'.TDOMF_MACRO_USERNAME.'/',tdomf_protect_input(get_post_meta($post_id,TDOMF_KEY_NAME,true)),$message);
Note the position of the ( ) brackets. Is this what you see?
Josh Kaufman said:
Thanks again for your help on this – you’ve been fantastically responsive!![]()
Thanks.
Though this week the demand for help has been much higher than previous weeks!
This isn’t working for me either. I’m trying everything you suggested to get the username to be the title but nothing seems to work. Do you have any other advice?
Also, as a less important sidenote, is there anyway for people who don’t want to deal with html tags to make clickable links in the form? Perhaps the addition of a button or something like how it is above this very form I’m typing in?
Adam said:
This isn’t working for me either. I’m trying everything you suggested to get the username to be the title but nothing seems to work. Do you have any other advice?
What version of the plugin are you using?
Also, as a less important sidenote, is there anyway for people who don’t want to deal with html tags to make clickable links in the form? Perhaps the addition of a button or something like how it is above this very form I’m typing in?
What do you mean “clickable links”? Could you be more specific because I’m not sure what you’re asking. If your talking abou the buttons above the comment form, yes you can have them in TDOMF too. There is an option in the Content widget called “Quicktags”. Enabling this will enable the button toolbar.
I’m using version 0.12.3 (build 40) of the plugin. I’ve tried appending all the bits of code you suggested but none seem to have any effect. Could there be some setting I don’t have enabled?
Quicktags. Right. Exactly what I was looking for – thank you so much.
Thank you so much for your quick response. This seems like something that should be doable but I can’t figure it out. There doesn’t seem to be anywhere in the code available in the form hacker that assigns the date/time as the default title.
Adam said:
I’m using version 0.12.3 (build 40) of the plugin. I’ve tried appending all the bits of code you suggested but none seem to have any effect. Could there be some setting I don’t have enabled?
How are you appending the bits of code? I assume your using the Append to Content widget and not the form hacker?
Thank you so much for your quick response.
No probs. I’m going on holidays next week so if I can’t fix it this week, it isn’t going to be fixed till August!
This seems like something that should be doable but I can’t figure it out. There doesn’t seem to be anywhere in the code available in the form hacker that assigns the date/time as the default title.
The Form Hacker can’t be used to assign the date/time for the title. The Form Hacker is used to modify the appearance of the Form only. As in, it only gets excuted when the Form is initially displayed. To add some code for after the post is submitted you have to use the “Append to Content” widget.
Adam said:
I should add that the “this post was submitted by…” works great so that’s not the issue.
Oh, I didn’t see that. I have it working on my test blog using this code in an Append to Content widget:
<p>Submitted by <?php echo %%USERNAME%% ?></p>
<?php $postdata = array(
"ID" => $post_id,
"post_title" => %%USERNAME%% );
sanitize_post($postdata,"db");
wp_update_post($postdata); ?>
I’m doing exactly that. I have the following widgets:
1. Who Am I (but I don’t have it showing anything since I want people to have to log in)
2. Content (I don’t have Title showing)
3. Upload Files
4. Append to Post Content 1 (with that code you suggested)
Nothing’s happening and when I go back to look at the appended code, it’s become:
$post_id,
\”post_title\” => %%USERNAME%% );
sanitize_post($postdata,\”db\”);
wp_update_post($postdata); ?>
Those slashes are going in. That can’t be good, right? Any other suggestions or reasons why this could not be working?
Adam said:
Those slashes are going in. That can’t be good, right? Any other suggestions or reasons why this could not be working?
Ack! Sounds like we have a magic quotes problem. Go into you’re phpinfo (from the main TDOMF page) and see for the “magic_quotes_gpc” variable. What is this set to?
It’s set to On in my configuration and I don’t get the slashes.
Adam said:
Also, that “this post was submitted by” thing just shows up, I don’t have it appended or anything.
There is an option that you can enable to do that automatically. You must have it enabled.
Okay, quick fix, open widgets/tdomf-append-widget.php and at line 71, change:
$newoptions['message'] = $_POST["append-message-$number"];
to
$newoptions['message'] = stripslashes($_POST["append-message-$number"]);
Then go to the Append to Content Widget, enter the code without the extra slashes and save it. Hopefully the slashes won’t appear again.
Adam said:
I thought you said yours is on and you don’t get slashes and mine is off and I am getting slashes. So I just need to turn it on so I can be like you. Right?
Eh, I guess. I’m not 100% it will work. You have magic quotes turned off yet you’re getting slashes. I don’t know why you would be getting slashes if magic quotes is turned off. You might end up with double slashes and turning on magic quotes won’t help.
You can turn on magic quotes a few ways. The method I use is to edit .htaccess file and add:
php_value magic_quotes_gpc 1
It totally worked!!! I put the stripslash command into the widget. Thank you so much! As long as I have you, can you tell me how I would change the appended code in case I want the title to say “posted by %%USERNAME%%.” I’m sure it’s simple, I just don’t want to muck about in there now that it actually works.
Adam said:
It totally worked!!! I put the stripslash command into the widget.
It’s only a quick fix. I’m not sure it’ll work it’s way into the main code base so be careful upgrading.
Thank you so much! As long as I have you, can you tell me how I would change the appended code in case I want the title to say “posted by %%USERNAME%%.” I’m sure it’s simple, I just don’t want to muck about in there now that it actually works.
I’m guessing it should be something like:
<?php $postdata = array(
"ID" => $post_id,
"post_title" => "Posted by %%USERNAME%%" );
sanitize_post($postdata,"db");
wp_update_post($postdata); ?>
Hmm…that doesn’t seem to work. I’ve tried a couple other options and they all end up defaulting back to the date as the title. If you’re not out the door yet, I’d love some help, but if you’re busy packing, don’t worry about it.
Enjoy your holiday and thank you so much for all your help.
admin
Guest
May 20th, 2008 at 9:04 am
I’d say the easiest way to do it is to create a form widget that you add as the last element of your form. For a simple example, look at widgets/tdomf-getcat-widget.php. Just make your own version of this file and put it in the widgets folder where it’ll get picked up by TDOMF.
If you do get it working, I’d be more than happy to add the widget to the release!
Permalink | Quote