By enjoylife-2 on
i used the hook_alter_form to add a field to the comment, when i submit a comment. why the field's content that i added can't show. why?
i used the hook_alter_form to add a field to the comment, when i submit a comment. why the field's content that i added can't show. why?
Comments
.
Did you add a custom submit function as well? ($form['#submit'][] = 'yourmodule_customsubmit')
no, how to write this line.
no, how to write that line. could you make me an example. if i want to the added field content show on the comment . many thanks.
.
If you store the values from that extra field, you'll want to load that when a comment gets loaded. That part is tricky. I'm trying to find a way to do that at the moment (didn't find any hooks like hook_comment_load or such, so it might have to be placed in hook_nodeapi, but let's hope it won't be thousands of comments, cause that'll hurt performance)
got it,many thanks.but
got it,many thanks.but hook_nodeapi is used to node, the comment in drupal isn't node. am i right?
oh,i am sorry., when i test it to my commet, it can't work. this is my code.
my comment save button is disappeared.
.
There's something odd with your switch statement. Dunno if it causes the save button to disappear, but it's bound to do odd things nonetheless.
Normally, the program you're writing the code in, should complain about that, and if not, at least the server will throw a big error when trying to run that code. Basically, you got to close the switch statement before closing the function. Also, I'd put $form['#submit'][] = 'my_submit_test'; within the case, not below it. Right now, it'll perform that submit function for every form on your site. If it's in the case, it'll do that only for comment_form.
You're right. Comments aren't nodes. They're attached to nodes, though. If comments are enabled, and you load a node using node_load(), you'll get all the comments as well. Same goes with the node object in hook_nodeapi. Try this code (but in a testing environment!), you'll see what I mean:
That code will show the entire structure of the node that's being shown (something regular visitors shouldn't see :P ). A quick search in there for comments will show you how you can alter comments using hook_nodeapi.
when i put the
when i put the $form['#submit'][]='my_submit_test'; on the break, it still can't work.
.
Can you post your entire hook_form_alter function here? Something's got to be wrong in it. It'll help seeing it completely, like how you run it, and not just a piece.
function
.
Errors must be turned off on your server, cause that code should give a fatal one :P You forgot a } to close the mymodule_form_alter function.
Try this instead:
yeah,you're right. you're my
yeah,you're right. you're my hero. but when i click the "save" button of the comment. i can't see the "hello world". why?
where is the hello world ?
.
Forms work as follow:
Step 2 is there to make sure people don't re-send a form when they refresh the page after having sent it.
What your submit function does, is return 'hello world' (might have meant print or echo, though) to that invisible page.
Usually, if you want to show the results from a submit callback, you'll have to set them in a session var, then print (or echo) that session var on a visible page (like the one where the form is shown). Don't forget to unset it afterwards.
Here's some example code to show you:
got it,if i put the
got it,if i put the some_function_showing_your_form() in a tpl.php file, i will get the hello world. am i right?
.
Technically, yes, but it's not good practice. Drupal follows the MVC principle. That means the presentation, actual code and data are all separated. It's better to call your form (using drupal_get_form) and passing that on as argument using the theme() function. I had a look at some other topics you made, and I guess you already understand hook_theme, so you'll know how to do this ;) If I'm mistaken, I don't mind explaining it, though.
many many thanks,you're a
many many thanks,you're a warm-hearted man. i know a little about the theme() function.only know all the drupal's output are by means of it. when i want to use a theme()function, i must be register it before(hook_theme). then call the theme function in this style: theme('hook_name','argument'). expect you can give me some more details to make me
refresh it. thank you.
.
Hook_theme():
Page callback:
example_page.tpl.php:
in your example where is the
in your example where is the theme function?your have registered a theme named 'example_page' that takes two argument, 'some_text' 'form' .
"some one told me before"
.
Had to look that way of doing it up :P I actually've never used theme_my_theme, but've always used .tpl.php files.
Basically, the example_page.tpl.php file does what your theme_my_theme function does. It's the same thing, except that you can give the .tpl.php file to a designer and they can do their job on it. With a theme_my_theme function, that's not possible. If it's to just show some text and a form, without a need for a designer to work on it, it's just as good, though. The only real difference is that you can pass a .tpl.php file on to a designer, while you can't pass the function on to him / her.
In your case, theme_my_theme might actually be the better way to go.
i know.you make me know a
i know.you make me know a lot.