views:

19

answers:

1

good morning, I have created a new content type - petition, a last step has to be verification of their mail address by sending them a link to prove or to delete them from the petition.

I need to get some sort of unique link which then I send as tokenized action mail to the mail account provided in the form. the tokenized link should then set their mail address valid and should be able to unpublish the post as well.

I am a bit desperate here, general directions are appreciated.

+1  A: 

Here's an example on how to change content of a node and how to send a mail when a node is created (but you can send a mail as well when a form is filled in). You should be able to adapt it to work with your setup.

A node is created and is not published by default. Here I will set the node as published when someone clicks a link in a mail.

Create a custom module that talks to the nodeapi:

function module_nodeapi($node, $op, $a3 = NULL, $a4 = NULL){

    if($node->type == 'petition'){
        switch ($op) {
            case 'submit':

            case 'insert':
                 $mail = $user->mail;
                 $nodeid = $node->nid;
                     // mail the user using the drupal_send_mail() function
                     // make the link something like: http://web.be/petition/validate/$nodeid/$mail
                     // drupal_set_message('thank you for validating the petition');
            case 'update':
            break;
        }
    }

So an example of the link is http://web.be/petition/validate/20/[email protected] . Next thing to do is use the hook_menu to get the link and it's variables (also in your custom module):

function module_menu(){
    $items['petition/valid/%/%'] = array(
        'title' => 'Validated your petition-entry',
        'page callback' => 'module_validate_petition',
        'page arguments' => array(1,2),
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
    );
}

function module_validate_petition($nid, $mail){
    // load the node
    $node = node_load($nid);
    // set to published
    $node->status = 1;
    // save the node
    node_save($node);
}
Jozzeh