not sure how to approach. I made a module that if the user hit Publish and hit a checkbox 'Send Email to follow Roles', that it will email the link of the Page to those roles.

Right now theres a emailsubject and emailbody textarea that pops up if you check that above option, so the content creator can fill that info.
But i want to prefill that Body field with something for them like 'Hey we just published this article, check it out click here'. In other words, if going to create Page first time to publish, content creator doesnt know the id of the node so in that body field, the link cant be prefilled out as i want it to be. Is there anyway to do something like the content creator will type in [articlelink]Click Here[/articlelink] into the node/add form's emailbody, and I can parse that and substitute node's link in nodeapi's submit $op?

Right now i think the only way to prefill this info, is to publish once without checking my checkbox, then coming back and the emailbody field can figure out the link since it has a node id created for it. Let me know if better solution.
Thanks!

Comments

kenuck’s picture

Hi ,

Instead of sending the email before the node is created, why not do a check in the formname_submit($node) hook for the email check box then inject the link in the email before sending it out?

cheers
-----------------------------------------
http://www.netrift.com
http://rlisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 5
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6

armyofda12mnkeys’s picture

well isnt hook_submit() called before the node is saved so no nid yet?

This is being added to the node/add form, so i dont have a custom submit function, im letting drupal handle all the normal node submission/validation stuff. can i add onto their submission routines or i have to hook somewhere so in addition my stuff gets checked after nid is set?

at worst i guess i can check the _nodeapi()'s $op for update and insert, cause $node at that point has a nid and form_values are global so i can check them there. have a better place to do this?

kenuck’s picture

nope,

node hook_submit($node) has the nid.

do a :

function mynode_form_submit($node) {

drupal_set_message(print_r($node,1)); 

}

to check the contents of $node.

cheers
-----------------------------------------
http://www.netrift.com
http://rlisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 5
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6

armyofda12mnkeys’s picture

I put that code and nothing happened. This is the hook_submit function right?
Sorry to be a pain for clarification, but how does the 'node/add' form know to use that submit function?
I understand that for pretend, if i had my own form called with drupal_get_form('mymodulecustomform'), then it automatically calls mymodulecustomform_submit() if thats available or if available uses '#submit' var in the form. (even so, the hook_submit function is called before insert so it wouldnt have the nid unless it was an update is my understanding based on hook_submit's api info "It is called after validation has succeeded and before insert/update".

But i dont have my own form... im just using _form_alter to add my form fields onto the existing node/add form ("node-form" form id). so it wont automatically look for hook_submit cause it has its own submission routines for that form right, aka if i did want to see when that form is submitted then i would use _nodeapi()'s $op=='submit' but again be stuck with no $nid for Inserts?

my best guess is to use _nodeapi()'s $op=='update' or 'insert' if the nodes nid is available at this point (aka after node insert).

Again, sorry im learning this stuff as i go. kinda learning more stuff as i read PDD book, but maybe im understanding wrong.
Thanks again for all the help.
Ari

kenuck’s picture

Sorry, my bad.

the hook function you're looking for is mynode_insert($node) .. :) or otherwise knows as the hook_insert() .. http://api.drupal.org/api/function/hook_insert/6

This function will be called after a node/add form submit.

cheers
-----------------------------------------
http://www.netrift.com
http://rlisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 5
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6

armyofda12mnkeys’s picture

ahhh ok i see that func... i do admit i might follow my orig plan, as the drupal api and PDD book also say: "To take action when nodes of any type are inserted (not just nodes of the type(s) defined by this module), use hook_nodeapi() instead.". So since this is a node form for any type being published and not just my own, ill use insert and update ops in nodeapi().
It was a good learning session. Thanks kenuck!